javascript 在 Google Map API 上获取缩放大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16272000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get zoom size on Google Map API
提问by MajAfy
How can I get the zoom size in google map after changing by mouse wheel or zoom bar ?
通过鼠标滚轮或缩放条更改后,如何在谷歌地图中获取缩放大小?
I use Google Map API 3 with JavaScript.
我使用带有 JavaScript 的 Google Map API 3。
I want to show in console.log()
with every change.
我想展示console.log()
每一个变化。
回答by Jordan Arseno
Easy. As per docs:
简单。根据文档:
google.maps.event.addListener(map, 'zoom_changed', function() {
var z = map.getZoom();
console.log(z);
});
Here's a great utilitythat shows all the events as they fire.
这是一个很棒的实用程序,可以在事件触发时显示所有事件。
回答by Cianan Sims
回答by Ankur Verma
You have to keep a div that will show the map I am having ('map_canvas').
你必须保留一个 div 来显示我拥有的地图('map_canvas')。
var map = new google.maps.Map(document.getElementById('map_canvas'), {
disableDefaultUI : true,
zoom : 12,
center : new google.maps.LatLng(17.1312321,78.23123123),
mapTypeId : google.maps.MapTypeId.ROADMAP
});
google.maps.event.addListener(map, 'zoom_changed',function() {
console.log(map.getZoom());
});