Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

javascript - jQuery Location Picker Plugin get zoom

How can I get zoom property in jQuery Location Picker Plugin? I can get map coordinates using currentLocation.latitude and currentLocation.longitude, but does any body know how to get zoom property?

$('#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 + ")");
}

when I try currentLocation.zoom I get undefined.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

since the plugin does not support that map-event, you'd have to bind it by yourself ...

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...