Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly use Google Maps API? [duplicate]

I found out, while using Google Maps API, the results change from time to time. By change I mean the response object. Basically I'm querying Google Maps to get a list of places based on user input (also using jQueryUI auto complete). I'm trying to correctly fetch the coordinates which get returned from Google Maps API but the properties containing the exact|approximate coordinates seem to change from time to time.

For example: in earlier days I was able to get coordinates like item.geocode.geometry.location.Ya and item.geocode.geometry.location.Za. Then my search form broke because Google changed it to item.geometry.location.mb and item.geometry.location.nb.

Any suggestions on how to implement this the correct, and stable way?

like image 359
Ben Fransen Avatar asked Mar 13 '13 20:03

Ben Fransen


People also ask

Is Google Maps API free for commercial use?

All Maps Embed API requests are available at no charge with unlimited usage.

Can Google maps show more than 20 results?

When using Google Place API, the result per a query is limited to 20.


1 Answers

Never use undocumented properties of a Maps API object like the ones you found. Those will change wildly whenever the Maps API is revised.

Instead, use only documented methods and properties.

Your item.geocode.geometry.location is a LatLng, so you can call its .lat() and .lng() methods:

var location = item.geocode.geometry.location;
var lat = location.lat();
var lng = location.lng();
like image 147
Michael Geary Avatar answered Dec 10 '22 10:12

Michael Geary