2017-09-15 89 views
0

我試圖在標記第一次或任何時候掉落時獲得latlng,但是我不能。 在我的代碼中,只有當標記處於打開狀態時,我才能得到latlng。用ng-map獲取標記的latlng angularjs

這是我的代碼:

<body> 
    <div ng-controller="MyCtrl"> 
    <ng-map 
    zoom="16" 
    center="{{address}}" 
    style="width:500px; height:400px" 
    scrollwheel = "false"> 
     <marker 
     position="{{address}}" 
     title="{{address}}" 
     on-dragend="getpos($event)" 
     animation="DROP" 
     draggable="true"> 
     </marker> 
    </ng-map> 
    <br/>Address : <input ng-model="data.dir" /> 
    <input type="button" name="" id="" value="buscar" ng-click="buscar()"/> 
    <br /> 
    {{data.emp_lat}}-----------{{data.emp_lon}} 
    </div> 
</body> 
</html> 

這是我的JS:

angular.module('ngMap').controller('MyCtrl', function($scope) { 
    $scope.data = {}; 
    $scope.address = 'toronto canada'; 
    $scope.buscar = function(){ 
    $scope.address = $scope.data.dir; 
    } 
    $scope.getpos = function(event){ 
     $scope.latlng = [event.latLng.lat(), event.latLng.lng()]; 
     $scope.data.emp_lat = event.latLng.lat(); 
     $scope.data.emp_lon = event.latLng.lng(); 
    }; 
}); 

我的問題是如何獲得的經緯度當標誌下降? (這應該發生後設定的地址在我的輸入)

感謝網友

回答

0

https://developers.google.com/maps/documentation/javascript/reference#Marker

你試過position_changed

https://plnkr.co/edit/0aIlq0iQfQkvU3nreVyY?p=preview

你可以嘗試創建一個plunker這下一次?

注意:您不應該直接將控制器添加到ng-map模塊中。

+0

我有這個https://plnkr.co/edit/9B7DMB9fq1b3Pitjsess?p=preview 我該如何實現position_changed? –

+0

謝謝@allenhwkim我要去嘗試你的朋友 –

+0

謝謝我的朋友allenhwkim你的回答是正確的:D:D –