2015-09-20 171 views
0

使用AngularJS谷歌地图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; 

现在,谷歌地图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; 

我不要编辑更多我的代码,我想我的代码稳定...有什么办法让坐标更稳定?

谢谢!

回答