javascript - map.setZoom() 不工作但 map.setCenter() 工作

标签 javascript google-maps google-maps-api-3 zooming

我的部分代码看起来像这样,我可以使用

将 map 居中
map.setCenter(myLatlng);

但在那之后我试图缩放 map

marker_id = id;
marker_id = new google.maps.Marker();

marker_id.setIcon(image);
myLatlng = new google.maps.LatLng(loctionupdateobj[id].lat, loctionupdateobj[id].lang);
marker_id.setPosition(myLatlng);        
marker_id.setMap(map);      

map.setCenter(myLatlng);

alert(map.getZoom());
map.setZoom(10);
alert("game again " + map.getZoom())

你可以看到

alert("game again " + map.getZoom())

在代码中,它会给我一个提示,例如 game again 10 但缩放级别永远不会达到 10

但第一个警报是 4(这是我在初始化时设置的)。

因为我无法setZoom,所以每次添加新标记时我都会创建一个新的 map 实例。

最佳答案

终于找到了!!! 之前为我的项目编写代码的程序员写了一行

google.maps.event.clearListeners(map);

关于javascript - map.setZoom() 不工作但 map.setCenter() 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17499712/

相关文章:

javascript - 将球从一个点弹到另一个点 - 矢量和加速度

google-maps - Openstreetmaps (OSM) 和 Google Maps(卫星 View )的 map 图 block

google-maps - 在哪里/如何从 Google Maps API 获取多边形数据?

javascript - 在谷歌地图中使用数组居中并打开 InfoWindow

javascript - 我的服务仅在我的 ngx 传单 map 上显示最后一个 json 元素标记

javascript - 使用socket.io与其他javascript文件nodejs和express发送和获取数据

javascript - 通过 moment.js 转换后,我得到了错误的日期

javascript - 如何在点击列表项时打开相应的标记信息窗口

google-maps - 我可以将 Google Places API 中的姓名、地址和纬度/经度存储在我自己的数据库中吗

css - Google Maps Api 未显示缩放按钮、街景或全屏图标?