Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieving lat/long of location using google.maps.geocoder

i have been trying to use some ajax to save venue location in my application and stumbled across the following code on stack overflow

function getLatLong(address) 
{
    var geocoder = new google.maps.Geocoder();
    var result = "";
    geocoder.geocode( { 'address': address, 'region': 'uk' }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            result[lat] = results[0].geometry.location.Pa;
            result[lng] = results[0].geometry.location.Qa;
        } else {
            result = "Unable to find address: " + status;
        }
    });
    return result;
}

my problem is when i call the function it returns nothing and when i debug and set breakpoints in chrome it breaks on return result first before it breaks on the result[lat] = results[0].geometry.location.Pa;

I know the array should be declared as type array but even when i was just returning the results[0].geometry.location object nothing was being returned

what can i do to return the lat/long of the location so i can store in my db?

like image 568
Chris Mccabe Avatar asked Jan 10 '12 16:01

Chris Mccabe


People also ask

How can I get latitude and longitude from address in Android?

The short story is you need to do: Geocoder geocoder = new Geocoder(this, Locale. getDefault()); List<Address> addresses = geocoder. getFromLocation(lat, lng, 1);

How do I find the geocode of a location?

One way to find your geolocation is to simply perform a lookup online. Melissa's Geocoder Lookup tool returns latitude, longitude, county, census tract and block data based on an address or ZIP Code. Simply enter the address or ZIP Code into the easy-to-use Lookups interface and submit.


1 Answers

This is not the answer but don't use Pa and Qa always use the lng() and lat() functions:

 place.geometry.location
{...}
    Pa: 56.240477
    Qa: -0.902655999999979
    toString: function(){return"("+this.lat()+", "+this.lng()+")"}
    equals: function(a){return!a?k:Cd(this.lat(),a.lat())&&Cd(this.lng(),a.lng())}
    lat: function(){return this[a]}
    lng: function(){return this[a]}
    toUrlValue: function(a){a=Hd(a)?a:6;return $d(this.lat(),a)+","+$d(this.lng(),a)}
like image 98
Lee Smith Avatar answered Oct 07 '22 18:10

Lee Smith