2015-09-20 233 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; 

我不要編輯更多我的代碼,我想我的代碼穩定...有什麼辦法讓座標更穩定?

謝謝!

回答