如何在Angularjs中使用ngMap访问地图标记的当前位置(lat, lng) ?



我有一个Angularjs网站,它使用ngMap从用户请求地理位置。看看这个活塞

<map center="current-location" zoom="16">
  <marker visible="true" centered="true" position="current-location" title="You are Here" draggable="true"></marker>
</map>

它工作得很好,但我怎么能访问(保存或打印)当前位置或标记的位置后,它被拖到不同的地方?

这不是你问题的解决方案,但希望能让你更接近你所需要的。请检查一下这个活塞

当你点击地图时,你正在创建一个标记并显示它的位置。

$scope.placeMarker = function(e) {
      var marker = new google.maps.Marker({position: e.latLng, map: map});
      $window.alert("position: " + e.latLng);
      map.panTo(e.latLng);
    }

希望能有所帮助。

这是一个访问标记位置(lat, lng)的方法。

$scope.$on('mapInitialized', function(evt, evtMap) {
    $scope.map = evtMap;
  });
  $scope.showMarkerLatlng = function(){
    alert($scope.map.markers[0].getPosition());
  }

最新更新