【问题标题】:angular-google-maps getting GEO location from mouse clickangular-google-maps 通过鼠标点击获取 GEO 位置
【发布时间】:2014-03-27 15:42:58
【问题描述】:

我正在使用来自http://angular-google-maps.org/ 的库 angular-google-maps。我能够让大部分工作正常进行。我目前正在努力的是让“点击”事件在地图上工作,从而为我提供点击位置的 GEO 位置。目前它甚至没有注册我正在点击地图。

这是我的部分:

<google-map 
    center="map.center"
    zoom="map.zoom"
    draggable='true'
    >


</google-map>

这里是控制器:

    // Create Map
    $scope.map = {
        center: {
            latitude: 40.296755,
            longitude: -111.696415
        },
        zoom: 13,
        events: {
            click: function (mapModel, eventName, originalEventArgs) {
                alert("hola?");
            }
        }

    };

任何帮助都会很棒!

【问题讨论】:

    标签: angularjs google-maps geolocation


    【解决方案1】:

    要将事件添加到地图,您需要将关联数组(对象)附加到指令的事件属性:

    <google-map events="$scope.events" .... ></google-map>
    

    在控制器中:

    $scope.events = {"click" : function () { console.log('woo-hoo') })
    

    【讨论】:

    • 我很抱歉。让我把那部分拿出来。这不是为了标记。我希望它出现在整个地图上。
    • 知道了。您需要将控制器中的事件对象定义为 google-map 指令中的属性。像这样:
    • 完美。这就是我需要的。如果您将此作为答案发布,我可以选择它作为解决方案。
    • 很高兴它成功了。我以前没有听说过 angular-google-maps,所以期待着玩弄它。我更改了上面的答案以反映更改。
    • 顺便说一句,我刚刚订阅了 angular-google-maps 作为标签。所以我现在应该可以更频繁地看到这些问题了。
    猜你喜欢
    • 1970-01-01
    • 2012-07-22
    • 2017-12-06
    • 2013-08-02
    • 2011-09-27
    • 2022-01-15
    • 1970-01-01
    • 2011-12-15
    相关资源
    最近更新 更多