Angularjs 谷歌地图:获取坐标
使用AngularJS和谷歌地图API我使用以下代码从地址获取坐标:Angularjs 谷歌地图:获取坐标,angularjs,google-maps,google-maps-api-3,Angularjs,Google Maps,Google Maps Api 3,使用AngularJS和谷歌地图API我使用以下代码从地址获取坐标: var geocoder = new google.maps.Geocoder(); geocoder.geocode({'address': address}, function (results, status) { if (status === google.maps.GeocoderStatus.OK) { var l
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
});
当我开始项目时,我只写了以下内容:
var lat = results[0].geometry.location.A
var lng = results[0].geometry.location.F;
随着时间的推移,Google Maps API将变量的名称更改为location.G和location.K,我需要为此重新编辑代码:
var lat = results[0].geometry.location.A || results[0].geometry.location.G;
var lng = results[0].geometry.location.F || results[0].geometry.location.K;
现在,谷歌地图API再次将变量的名称更改为location.H和location.L
新代码:
我不想编辑更多代码,我希望代码稳定。。。有没有办法使坐标更稳定?
谢谢 这看起来像是这个问题的重复: 答案是: “使用记录的属性,它们不会更改。
几何体。位置
是一个google.maps.LatLng
对象,记录的方法有:
lat()
number以度为单位返回纬度。
lng()
number返回以度为单位的经度。”
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;