views:

149

answers:

3

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;amp;file=api&amp;amp;v=2&amp;amp;sensor=true&amp;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>
A: 

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

Galen
exactly, i have the same results!
camelCase
A: 

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.

adamse
A: 

Well - it's actually doing geolocation!

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

broady