Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google.maps.Geocoder.geocode() geometry.location lat/lng property names change frequently

I have an application, and I'm using the Google Javascript Geocoding API to fetch lat/lng for an address.

The code goes something like

geocoder = new google.maps.Geocoder() geocoder.geocode({ 'address': query }, function(results, status) {     addresses = {};     $.each(results, function(index, value){         addresses[index] = {"lat":value.geometry.location.$a,"lng":value.geometry.location.ab}     }) }); 

All is fine and dandy, but the thing is that the property names of the location object periodically change. Each time they change, my site breaks.

Twice I've had to change my code to accommodate the weird lat/lng property name changes in google's geolocation api. Originally it was Xa, Ya, then I had to change to Ya, Za, and now its $a, ab. I don't see any user friendly logic behind these changes.

Does anyone know why these property names change, and/or what strategy can I use to obtain the lat/lng while avoiding the problems caused by these property name changes?

like image 271
tomwoods Avatar asked Nov 21 '12 17:11

tomwoods


People also ask

How do I find the geocode on Google Maps?

Go to the Google Cloud Console. Click the Select a project button, then select the same project you set up for the Maps JavaScript API and click Open. From the list of APIs on the Dashboard, look for Geocoding API. If you see the API in the list, you're all set.

What is Geocoder map?

Geocoding is the process of converting addresses (like a street address) into geographic coordinates (like latitude and longitude), which you can use to place markers on a map, or position the map. Reverse geocoding is the process of converting geographic coordinates into a human-readable address.

Which is the best method to use to geocode a static list of address?

Use the Geocoding API web service. Recommend automated systems use the Geocoding API web service.

How do I find the latitude and longitude of a geocoder address?

The short story is you need to do: Geocoder geocoder = new Geocoder(this, Locale. getDefault()); List<Address> addresses = geocoder. getFromLocation(lat, lng, 1);


1 Answers

Use the documented properties, they will not change

geometry.location is a google.maps.LatLng object, the documented methods are:

lat()   number  Returns the latitude in degrees. lng()   number  Returns the longitude in degrees. 
like image 80
geocodezip Avatar answered Sep 29 '22 03:09

geocodezip