Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  144] [ 5]  / answers: 1 / hits: 36991  / 12 Years ago, fri, may 18, 2012, 12:00:00

I'm testing out the Google Places autocomplete feature here:



https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete



I want to get the latitude and longitude of the Place, but I'm having some troubles. When I use the following code:



var place = autocomplete.getPlace();
console.log(place.geometry.location);


I get this returned:



enter



When I use it in an infoWindow like this:



infowindow.setContent('
<div><strong>' + place.name + '</strong><br>' + place.geometry.location);


place.geometry.location is then displayed like this:




(53.539834, -113.49402099999998)




All I want to do is get the lat and lng separately. place.geometry.location.lat doesn't work. Not sure what else to do.


More From » google-maps

 Answers
22

You can use like this.



var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();

[#85506] Wednesday, May 16, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
miles

Total Points: 256
Total Questions: 111
Total Answers: 104

Location: Benin
Member since Fri, Mar 24, 2023
1 Year ago
;