角谷歌 - 地图:在控制器中如何使用“方法” [英] Angular-Google-Maps: How to use 'method' in the controller

查看:264
本文介绍了角谷歌 - 地图:在控制器中如何使用“方法”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

 标记=新google.maps.Marker(选);
现在的位置= marker.getPosition();


解决方案

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

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

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

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

老答案:
它是目前不可能的:
<一href=\"https://github.com/nlaplante/angular-google-maps/issues/277\">https://github.com/nlaplante/angular-google-maps/issues/277

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

指令调用:

 &LT;谷歌地图中心=中心变焦=放大控制=GoogleMap的&GT;&LT; /谷歌地图&GT;

角控制器:

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

这篇关于角谷歌 - 地图:在控制器中如何使用“方法”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆