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

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

问题描述

我有一个应用程序,我正在使用Google Javascript地理编码API为地址提取纬度/经度。



代码类似于

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

一切都很好,很花哨,但是位置对象的属性名称会周期性变化。每次他们改变,我的网站就会中断。



两次我必须更改我的代码以适应Google地理位置api中奇怪的纬度/经度属性名称更改。最初是Xa,Ya,然后我不得不换到Ya,Za,现在换成$ a,ab。我没有看到这些变化背后的用户友好逻辑。



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

使用属性,它们不会改变



geometry.location is一个 google.maps.LatLng 对象,文档化的方法是:

  lat()数字以度为单位返回纬度。 
ng()数字以度为单位返回经度。


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?

解决方案

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.

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

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