this is my simple code I'm using in a test page: but it takes ages to find the address...how come? am i doing something wrong?
<script src="http://maps.google.com/maps?hl=it&file=api&v=2&sensor=true&key=*xxxxxx*" type="text/javascript"></script> <script type="text/javascript"> var map; var geocoder; function addAddressToMap(response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to geocode that address"); } else { place = response.Placemark[0]; point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); document.getElementById('address').innerHTML = place.address; } } function searchGeolocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { geocoder = new GClientGeocoder(); document.getElementById('latitude').innerHTML = position.coords.latitude; document.getElementById('longitude').innerHTML = position.coords.longitude; coordinates = position.coords.latitude+","+position.coords.longitude; geocoder.getLocations(coordinates, addAddressToMap); }); }else { document.getElementById('latitude').innerHTML = "Unknown"; document.getElementById('longitude').innerHTML = "Unknown"; document.getElementById('address').innerHTML = "Unknown"; alert("I'm sorry, but geolocation services are not supported by your browser."); } } </script> <br/> latitude = <div id="latitude">loading...</div> <br/> longitude = <div id="longitude">loading...</div> <br/> address = <div id="address">loading...</div> <br/> <script type="text/javascript"> searchGeolocation(); </script>
IP-based geolocation services provide 55 percent to 80 percent accuracy for a user's region or state. And they provide 50 percent to 75 percent accuracy for a user's city. In practice, the actual accuracy may vary from provider to provider and depending on the location of the device.
Geolocation sources Mobile devices tend to use triangulation techniques such as GPS (accurate to 10m and only works outside), WiFi and GSM / CDMA cell IDs (accurate to 1000m).
The Geolocation. getCurrentPosition() method is used to get the current position of the device.
Well - it's actually doing geolocation!
To speed it up, consider providing the extra parameters for utilising cached results, and a timeout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With