【发布时间】:2015-09-20 15:42:37
【问题描述】:
使用 AngularJS 和 Google Maps API 我使用以下代码从地址获取坐标:
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;
现在,Google Maps API 再次将变量名称更改为 location.H 和 location.L...
新代码:
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;
我不想编辑更多我的代码,我希望我的代码稳定...有什么方法可以让坐标更稳定?
谢谢!
【问题讨论】:
标签: angularjs google-maps google-maps-api-3