2017-01-02 10 views
0

私のプロジェクトでは、私はGoogleマップを統合しました。私は1つの問題を抱えています:特定の場所を検索するとき、マーカーは現在の点に表示されていない、別の場所に表示されています。しかし、緯度と経度は正しいです、私が逃しているものを理解するのを助けることができますか?Googleマップのマーカーが正確な場所に表示されていません

注:一部の地域では、マーカーが正しい場所に表示されます。

HTMLコード:

<input ng-model="address" class="form-control" ng-map-autocomplete/> 
<ng-map zoom="18" center="{{address}}" style="width:650px; height:450px"> 
    <marker position="{{address}}" title="{{address}}" draggable="true"></marker> 
</ng-map> 

は、コントローラ:

$scope.$watch(function ($scope) { return $scope.chosenPlaceDetails }, function() { 
    if (angular.isDefined($scope.chosenPlaceDetails)) { 
     $scope.latitude= $scope.chosenPlaceDetails.geometry.location.lat(); 
     $scope.longitude=$scope.chosenPlaceDetails.geometry.location.lng(); 
    } 
}); 

答えて

0

NG-マップオートコンプリートドキュメントによれば、{{アドレス}}は、オートコンプリートのために使用される唯一の値です。あなたの位置の緯度と経度を含む「詳細」値を添付することができます。

<input type="text" ng-map-autocomplete ng-model="autocomplete" options="options" details="details"/> 

次に、あなたのNG-MAPディレクティブでは、あなたがあなたのコントローラ内で更新したい場合は、詳細

に$ウォッチャーを置くことができます
<ng-map zoom="18" center="{{details.geometry.location.lat}},{{details.geometry.location.lng}}" style="width:650px; height:450px"> 
    <marker position="{{details.geometry.location.lat}},{{details.geometry.location.lng}}" title="{{address}}" draggable="true"></marker> 
</ng-map> 

緯度と長いにアクセスすることができます
$scope.$watch('details', function (newValue, oldValue) { 
if (oldValue == undefined){ 
    $scope.latitude = 0 /*default value */ 
    $scope.longitude= 0 /*default value */ 
} 
$scope.latitude= newValue.geometry.location.lat; 
$scope.longitude=newValue.geometry.location.lng; 
}); 

新しい変数でng-mapディレクティブの位置にアクセスできます。

<ng-map zoom="18" center="{{latitude}},{{longitude}}" style="width:650px; height:450px"> 
    <marker position="{{latitude}},{{longitude}}" title="{{address}}" draggable="true"></marker> 
</ng-map> 

希望します。 出典:Psのhttps://github.com/iazi/ngMapAutocomplete

:コードテストされていません、私は単に私はヶ月前

+0

、コントローラのコードを変更する方法をやったことを再作成してみてください。.. –

+0

あなたがコントローラでも更新したい場合は、多分置きます詳細変数の$ウォッチャー '$スコープ。$ watch( 'details'、function(newValue、oldValue){ $ scope.latitude = newValue.geometry.location.lat; $ scope.longitude = newValue.geometry位置.lng } }); ' – Roux

+0

こんにちは私のコントローラのRoux私はこのような初期値を与えています:\t $ scope.address =" 12180 Park Ave S、Tacoma、WA 98447、USA "; \t $ scope.lat = "47.146427232895235"; \t $ scope.lng = " - 122.4420750597717"; –

関連する問題