The Google Places API, why does it return Lat and Lon each time under a different variable?

This drives me crazy, for some reason the API used Lat and Lon to return: (I think it was):

place.geometry.location.y as Latitude
place.geometry.location.z as longitude

Then he began to return it as follows:

place.geometry.location.Ya as Latitude
place.geometry.location.Za as longitude

And today my APP did not work, and I found that it was because the Google API returned Lat and Lon like this:

place.geometry.location.$a as Latitude
place.geometry.location.ab as longitude

WTF? How should I work with this? I think by simply reading the first variable inside the locations as Latitude, and the second as longitude, regardless of their names. But I'm afraid that next time the API might return a completely different object and ruin my javascript.

Has anyone experienced this? What should I do?

+1
javascript
Nov 22
source share
1 answer

place.geometry.location consists of the LatLng class. Therefore, if you want to get Latitude / Longitude, you should use this code:

 var lat = result[0].geometry.location.lat(); var lng = result[0].geometry.location.lng(); 

Here is the link place.geometry.location. https://developers.google.com/maps/documentation/javascript/reference#PlaceGeometry

+8
Nov 22
source share



All Articles