【问题标题】:jQuery Location Picker Plugin get zoomjQuery 位置选择器插件获取缩放
【发布时间】:2019-01-30 22:26:19
【问题描述】:

如何在 jQuery 位置选择器插件中获取缩放属性?我可以使用currentLocation.latitudecurrentLocation.longitude 获取地图坐标,但是有人知道如何获取缩放属性吗?

$('#the-map').locationpicker({
location: {latitude: 46.15242437752303, longitude: 2.7470703125},
radius: 300,
onchanged: function(currentLocation, radius, isMarkerDropped) {
    alert("Location changed. New location (" + currentLocation.latitude + ", " + currentLocation.longitude + ")");
}

当我尝试currentLocation.zoom 时,我得到了未定义。

【问题讨论】:

    标签: javascript jquery google-maps jquery-plugins


    【解决方案1】:

    由于插件不支持该地图事件,您必须自己绑定它...

    google.maps.event.addDomListener(window, 'load', function() {
    
      $('#map_canvas').locationpicker({
          location: {latitude: 40.7324319, longitude: -73.82480777777776},
          radius: 300
      });
    
      /* bind the zoom_changed event for the plugin's map handle */
      $('#map_canvas').data('locationpicker').map.addListener('zoom_changed', function() {
        var map = $('#map_canvas').data('locationpicker').map;
        console.log('zoom level: ' + map.getZoom());
      });
    
    });
    html, body, #map_canvas {height: 100%; width: 100%; margin: 0px; padding: 0px;}
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="//maps.googleapis.com/maps/api/js"></script>
    <script src="//rawgit.com/Logicify/jquery-locationpicker-plugin/master/dist/locationpicker.jquery.js"></script>
    <div id="map_canvas"></div>

    【讨论】:

    • 这就是您设置缩放的方式。我需要在用户更改地图时获取地图的当前缩放比例
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 2012-05-09
    • 2013-03-02
    • 2017-12-24
    • 2011-09-23
    • 1970-01-01
    • 2018-10-16
    相关资源
    最近更新 更多