【问题标题】:How to get geo coordinates on clicked location of map using Angular-Leaflet-directive?如何使用 Angular-Leaflet-directive 获取地图点击位置的地理坐标?
【发布时间】:2015-04-09 02:46:42
【问题描述】:

如何使用传单获取点击位置的地理坐标? 我尝试类似..

  $scope.$on('leafletDirectiveMap.geojsonClick', function (e) {
             alert("Lat, Lon : " + e.latlng.lat + ", " + e.latlng.lng)
    });

但是没有用。

【问题讨论】:

    标签: angularjs leaflet angular-leaflet-directive


    【解决方案1】:

    angular-leaflet 在第二个参数中包含常规传单事件。 Alos,您只需要像普通传单一样的 'click',但带有 'leafletDirectiveMap' 前缀。

    jsfiddle


     $scope.$on('leafletDirectiveMap.click', function (e, wrap) {
             alert("Lat, Lon : " + wrap.leafletEvent.latlng.lat + ", " + wrap.leafletEvent.latlng.lng)
    });
    

    【讨论】:

    • 我试过了,但还是不行。它在控制台中返回错误。 TypeError:无法读取未定义的属性“纬度”
    • 啊!弄清楚了。在事件中插入console.log(arguments) 后,看起来带有地理信息的传单事件在第二个参数中。
    【解决方案2】:
    .controller('MapController', function (leafletData) {
                      leafletData.getMap().then(function(map) {
                           map.on('click', function(e) {
                             console.log("Latitude : " + e.latlng.lat + " Longitude :  "+ e.latlng.lng);
                        });
                  });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-03
      • 1970-01-01
      • 2017-12-06
      • 1970-01-01
      • 2015-03-09
      • 2011-06-21
      • 1970-01-01
      • 2021-08-26
      相关资源
      最近更新 更多