2017-07-26 8 views
-1

Googleマップのapiでアドレスから緯度と経度を取得しようとしていますが、それはどうしても得られません。マップはアドレスを取得することによって動作していますが、そのアドレスが緯度と経度を取る方法がありますか?次のコードは動作しています:緯度と経度は保存されていませんGoogleマップ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と長いが、常にデータベースにsalvedされていないヌルであり、理由がわからないということですが..

$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

同様の問題は、Googleマップで住所から緯度\ 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

関連する問題