0

Using AngularJS and Google Maps API I'm getting the coordinates from an address using this code:

  var geocoder = new google.maps.Geocoder();
            geocoder.geocode({'address': address}, function (results, status) {

                if (status === google.maps.GeocoderStatus.OK) {
                    var lat = results[0].geometry.location.A || results[0].geometry.location.G || results[0].geometry.location.H;
                    var lng = results[0].geometry.location.F || results[0].geometry.location.K || results[0].geometry.location.L;

                   //Something to do
            });

When I started the project I write only this:

var lat = results[0].geometry.location.A 
var lng = results[0].geometry.location.F;

In the pass of time, the Google Maps API changed the name of the variables to location.G and location.K and I needed to re-edit the code for this:

var lat = results[0].geometry.location.A || results[0].geometry.location.G;
var lng = results[0].geometry.location.F || results[0].geometry.location.K;

Now, the Google Maps API changed again the name of the variables to location.H and location.L...

New code:

var lat = results[0].geometry.location.A || results[0].geometry.location.G || results[0].geometry.location.H;
var lng = results[0].geometry.location.F || results[0].geometry.location.K || results[0].geometry.location.L;

I don't want to edit more my code, I want my code stable... Is there any way to get the coordinates more stable?

Thanks!

Aral Roca
  • 5,442
  • 8
  • 47
  • 78

1 Answers1

1

This looks like a repeat of this question:

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

The answer is:

"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."

Community
  • 1
  • 1
NineToeNerd
  • 307
  • 5
  • 17