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

亡梦爱人 提交于 2019-12-27 23:37:08

问题


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?


回答1:


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.


来源:https://stackoverflow.com/questions/13499111/google-maps-geocoder-geocode-geometry-location-lat-lng-property-names-change-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!