2017-01-02 1 views
0

내 프로젝트에서 Google지도를 통합했습니다. 한 가지 문제가 있습니다. 특정 위치를 검색 할 때 마커가 현재 위치에 표시되지 않고 다른 위치에 표시되고 있습니다. 그러나 위도와 경도가 정확합니다. 제가 누락 된 부분을 이해하도록 도와 줄 수 있습니까?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

잉 맵을 자동 완성 문서에 따르면, {{주소}}만을 자동 완성에 사용되는 값이다. 위치의 위도와 경도를 포함하는 '세부 정보'값을 첨부 할 수 있습니다.

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

그런 다음, NG-지도 지침, 당신은 세부 사항에 위도와 당신이 컨트롤러에 업데이트하려면

<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> 

희망이 있습니다. 출처 : https://github.com/iazi/ngMapAutocomplete

시가 : 코드는 테스트하지, 난 단지 당신이 컨트롤러도 업데이트 할 경우 전

+0

어떻게 .. 다음 –

+0

을 컨트롤러에 코드를 변경 한 달 무슨 짓을했는지 다시 시도, 어쩌면 넣어 세부 변수의 $ watchcher $ scope. $ 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"; –

관련 문제