dallen dallen - 10 months ago 61
Javascript Question

PlaceResult object returns latitude/longitude as object, not sure how to get them individually

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


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();

I get this returned:

enter image description here

When I use it in an infoWindow like this:

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

is then displayed like this:

(53.539834, -113.49402099999998)

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

Answer Source

You can use it like this.

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