Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geolocation is so slow! what I'm doing wrong?

Tags:

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&amp;file=api&amp;v=2&amp;sensor=true&amp;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> 
like image 404
Francesco Avatar asked Sep 20 '10 14:09

Francesco


People also ask

What is a geolocation accuracy?

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.

How accurate is navigator geolocation?

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).

Which function is used to get the current position using geolocation API?

The Geolocation. getCurrentPosition() method is used to get the current position of the device.


1 Answers

Well - it's actually doing geolocation!

To speed it up, consider providing the extra parameters for utilising cached results, and a timeout.

like image 166
Chris Broadfoot Avatar answered Sep 22 '22 14:09

Chris Broadfoot