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?
The short story is you need to do: Geocoder geocoder = new Geocoder(this, Locale. getDefault()); List<Address> addresses = geocoder. getFromLocation(lat, lng, 1);
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.
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)}
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