2017-07-26 54 views
-1

我想從谷歌地圖API的地址獲取經度和緯度,我不明白它如何。地圖通過獲取地址來工作,但是有一種方法可以使地址獲得經緯度?下面的代碼工作:經緯度未保存谷歌地圖API

<ng-map default-style="false" zoom="16" center="{{ '{{ getAddress() }}' }}" style="width: 100%; height: 430px;"> 
       <marker centered="true" position="{{ '{{ getMarkerPosition() }}' }}" draggable="true" on-dragend="onMarkerDragEnd($event)"></marker> 
       <shape ng-if="showRegions" ng-repeat="shape in regions" 
         (...) 
       </shape> 
</ng-map> 

而且JS:

$scope.getMarkerPosition = function() { 
      if (!$scope.address.mapPinLocationLatitude || !$scope.address.mapPinLocationLongitude) { 
       return $scope.getObjectiveAddress(); 
      } 

      return [$scope.address.mapPinLocationLatitude, $scope.address.mapPinLocationLongitude] 
     }; 

的問題是,mapPinLocationLatitude和長總是空,在數據庫中沒有獲救,不知道爲什麼..

$scope.getAddress = function() { 
      var address = "..."; (here just concatenate the string with the address values(street, number, etc and it returned) 

      return streetString + ', ' + address; 
     }; 


    $scope.onMarkerDragEnd = function ($event) { 
      $scope.address.mapPinLocationLatitude = $event.latLng.lat(); 
      $scope.address.mapPinLocationLongitude = $event.latLng.lng(); 
      $scope.updateRegions(); 
     }; 

所以,我的問題是,任何想法如何獲得緯度和長期,例如,如果我寫:地圖要正確顯示?

<marker centered="true" position="{{ '{{ [address.mapPinLocationLatitude, address.mapPinLocationLongitude]}}' }}" draggable="true" on-dragend="onMarkerDragEnd($event)"></marker> 
+0

你想獲得類似的問題LAT \ LNG從谷歌地圖的地址? – Constantine

+0

是的,這是我想要的 – IleNea

回答

0
使用

geocoding service

Example

$.getJSON({ 
url : 'https://maps.googleapis.com/maps/api/geocode/json', 
data : { 
    sensor : false, 
    address : address 
}, 
success : function(data, textStatus) { 
    console.log(textStatus, data); 
} 

});

堆棧here

相關問題