I don't want to have the user install Google Gears so I can show him his guessed location. Is there a way to get the location without having to use Google Gears?
I have found http://www.wipmania.com/de/blog/google-geolocation-api/ but it does not offer an example.
Google provides a way to get the user location via it's AJAX API loader. This will even work without Gears installed. Simply include a script tag pointing to the JsAPI:
<script type="text/javascript"
src="http://www.google.com/jsapi?key=ABCDEFG">
</script>
When an application makes use of the AJAX API loader, the loader attempts to geo locate the client based on it's IP address. If this process succeeds, the client's location, scoped to the metro level, is made available in the google.loader.ClientLocation property. If the process fails to find a match, this property is set to null.
if (google.loader.ClientLocation){
var center = new google.maps.LatLng(
google.loader.ClientLocation.latitude,
google.loader.ClientLocation.longitude
);
map.setCenter(center);
}
When populated, the google.loader.ClientLocation object is populated with the following metro-level granularity properties:
ClientLocation.latitude
— supplies the low resolution latitude associated with the client's IP addressClientLocation.longitude
— supplies the low resolution longitude associated with the client's IP addressClientLocation.address.city
— supplies the name of the city associated with the client's IP addressClientLocation.address.country
— supplies the name of the country associated with the client's IP addressClientLocation.address.country_code
— supplies the name of the ISO 3166-1 country code associated with the client's IP addressClientLocation.address.region
— supplies the country specific region name associated with the client's IP address