代码之家  ›  专栏  ›  技术社区  ›  Dimoreno

使用ng map angularjs获取标记的latlng

  •  0
  • Dimoreno  · 技术社区  · 7 年前

    我试着在标记器第一次或任何时候下降时获得latlng,但我做不到。

    这是我的代码:

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

    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();
        };
    });
    

    我的问题是,当标记器下降时,我如何获得latlng? (这应该在我的输入中设置地址后发生)

    谢谢朋友们

    1 回复  |  直到 7 年前
        1
  •  0
  •   allenhwkim    7 年前

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

    你试过了吗 position_changed

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

    注意:不应将控制器直接添加到ng map模块。