google.maps.Geocoder.geocode() geometry.location lat/lng 属性名称经常更改 [英] google.maps.Geocoder.geocode() geometry.location lat/lng property names change frequently

查看:27
本文介绍了google.maps.Geocoder.geocode() geometry.location lat/lng 属性名称经常更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我正在使用 Google Javascript Geocoding API 来获取地址的纬度/经度.

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

代码类似于

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.

我不得不两次更改代码以适应 google 地理定位 api 中奇怪的 lat/lng 属性名称更改.原来是Xa,Ya,后来不得不改成Ya,Za,现在是$a,ab.我没有看到这些更改背后有任何用户友好的逻辑.

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.

有谁知道为什么这些属性名称会发生​​变化,和/或我可以使用什么策略来获取 lat/lng 同时避免这些属性名称更改引起的问题?

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?

推荐答案

使用文档化的 属性,它们不会改变

Use the documented properties, they will not change

geometry.location 是一个 google.maps.LatLng 对象,记录的方法是:

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.

这篇关于google.maps.Geocoder.geocode() geometry.location lat/lng 属性名称经常更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆