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

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>

Answers


I've found that the speeds are a lot different depending on the browser. I've been testing my geolocation with chrome, because that is almost instant. Firefox is slow as hell (lots of the time it doesnt even work), and safari is in second. Hopefully in time they will fix their implementation so it's as fast as chrome's


Well - it's actually doing geolocation!

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


Check your mobile device's Location service mode. Make sure the accuracy is in High status on your devide. The High accuracy mode uses GPS, WIFI or Mobile network to find the location.

If you choose Low or GPS only mode it takes forever.

Also play with the geo location option and give the timeout and cache options.


A couple of your calls might take some seconds to finish, for example navigator.geolocation.getCurrentPosition takes up to 5 sec (when working) for me in Safari.


I've been struggling with that for a couple of hours now and it turned out that it is a different result for each browser aka it is something that code can't fully control but you can do some progress by adding these options to getlocation.getCurrentPosition function call:

enableHighAccuracy: false,
timeout: 5000,
maximumAge: Infinity

You can read more about the meaning of each option here


Need Your Help

Can't include <gl/gl.h>

opengl include redefinition

I'm using Visual Studio 2010.

Silverlight: Find all controls of type in layout

.net silverlight controls silverlight-3.0 children

I'm looking for a reliable method to build a list of controls of &lt;Type> contained in a specific &lt;Panel> derived control - this includes those that are direct children, and those which are chi...