角谷歌 - 地图:在控制器中如何使用“方法”如何使用、器中、地图、方法

2023-09-13 04:06:45 作者:罂粟狠美,却有毒

当我从jQuery的方式改变我的应用程序角的方式,我尝试用角谷歌-地图。

但我找不到哪里是谷歌地图对象(地图,标记,多边形...)并且该方法使用对象的方法(例如像的GetMap()的getPath(),为getPosition()..)。

如果我需要得到它拖到标记的位置,我该怎么办?就像我平时做?

 标记=新google.maps.Marker(选);现在的位置= marker.getPosition(); 
Jmeter性能测试中常用控制器 仅一次控制器 的使用方法

解决方案

编辑:我找到了一种方法如何获得标记的位置,当它被dragged'n'dropped。您可以设置回调函数标记:

 <谷歌地图中心=中心变焦=放大控制=GoogleMap的>   <标记COORDS =COORDS选项=选项事件=事件>< /谷歌地图> 

然后在你的控制器定义回调:

  $ scope.events:{               dragend:功能(标记){                  $ rootScope。$应用(函数(){                     的console.log(marker.position.lat());                     的console.log(marker.position.lng());                  });               }            } 

老答案:它是目前不可能的:https://github.com/nlaplante/angular-google-maps/issues/277

不过,您可以得到原始google.maps.Map对象:

指令调用:

 <谷歌地图中心=中心变焦=放大控制=GoogleMap的>< /谷歌地图> 

角控制器:

  ...$ scope.center = = {            纬度:48.13171,            经度:11.549554         };$ scope.zoom = 8;$ scope.googleMap = {}; //这是在谷歌地图启动填补功能getMapObject(){   $ scope.googleMap.control.getGMap();}... 

When I change my app from jQuery way to Angular way, I try to use Angular-Google-Maps.

But I can't find where is the Google Map Objects(Map, Marker, Polygon...) and the approach to use Object 'method' (such like getMap() , getPath(), getPosition()..).

If I need to get the position of the marker which is dragged, how can i do? just like I usually do ?

marker = new google.maps.Marker(opts);
postion = marker.getPosition();

解决方案

Edit: I found a way how to get the marker position when it was dragged'n'dropped. You can set the callback function for the marker:

<google-map center="center" zoom="zoom" control="googleMap">
   <marker coords="coords" options="options" events="events">
</google-map>

Then in the controller you define the callback:

$scope.events: {
               dragend: function (marker) {
                  $rootScope.$apply(function () {
                     console.log(marker.position.lat());
                     console.log(marker.position.lng());
                  });
               }
            }

Old Answer: It is currently not possible: https://github.com/nlaplante/angular-google-maps/issues/277

However, you can get the original google.maps.Map object:

Directive call:

<google-map center="center" zoom="zoom" control="googleMap"></google-map>

Angular controller:

...
$scope.center = = {
            latitude: 48.13171,
            longitude: 11.549554
         };
$scope.zoom = 8;
$scope.googleMap = {}; // this is filled when google map is initiated

function getMapObject() {
   $scope.googleMap.control.getGMap();
}
...