【问题标题】:how to get center_changed latitude and longitude in angular google map如何在角度谷歌地图中获取center_changed纬度和经度
【发布时间】:2017-03-09 08:26:19
【问题描述】:

我正在使用角度谷歌地图https://angular-ui.github.io/angular-google-maps/#!/。当用户拖动地图时。我需要像 ola 或 uber 应用程序一样获取他的中心纬度和经度。

我在这个链接中有一个演示,但是这个演示在拖动时显示 lat 和 lng http://googlemaps.googlermania.com/google_maps_api_v3/en/map_example_21.html

我不知道如何执行此操作。下面是我的代码。请帮我。任何帮助都应该不胜感激。提前致谢

$scope.map = {
              center: {
                latitude: $scope.set_latitude, //current location
                longitude: $scope.set_longitude
              },
              control: {}, 
              zoom: 12, 
              bounds: {},
              events:
                  { 
                    dragend: function (mapModel, eventName, marker, orignalEventArgs) {
                        alert('dragend');
                    }, 
                    tilesloaded: function(map, eventName, originalEventArgs){

                    var e = originalEventArgs[0]; 
                        var ret = {
                            id: 0,
                            latitude: $scope.set_latitude, // marker current location
                            longitude: $scope.set_longitude, 
                            title: 'Your Location',
                            icon:'image/marker.png'
                          };  

                          $scope.randomMarkers.push(ret); 
                    }

                  } ,

                  markersEvents: {
                    click: function(marker, eventName, model) { 
                        $scope.map.window.model = model;
                        $scope.map.window.show = true;
                    }
                  },    
                  window: {
                    marker: {},
                    show: false,
                    closeClick: function() {
                      this.show = false;
                    },
                    options: {}
                  }
            };

【问题讨论】:

    标签: angularjs google-maps google-maps-api-3


    【解决方案1】:

    在谷歌地图活动上进行了长时间的锻炼后,我自己找到了答案。

    要获取 dragend lat 和 lng 详细信息,请更改此代码

    dragend: function (mapModel, eventName, marker, orignalEventArgs) {
       alert('dragend');
    }
    

    dragend: function (map, eventName) {
        var center = map.getCenter();
        $scope.latitude_n = center.lat();
        $scope.longitude_n = center.lng(); console.log($scope.latitude_n+','+$scope.longitude_n); // center location details
    },
    

    如果您想要 center_changed 事件 lat 和 lng 详细信息,请添加此代码

    center_changed:function (map, eventName){
        var center = map.getCenter();
        $scope.latitude_n = center.lat();
        $scope.longitude_n = center.lng(); console.log($scope.latitude_n+','+$scope.longitude_n); // center location details
    },
    

    祝你好运。干杯。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-03
      • 1970-01-01
      相关资源
      最近更新 更多