Google地图放大标记 [英] Google maps zoom in on marker

查看:72
本文介绍了Google地图放大标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Maps API.当我单击地图标记时,我希望地图放大一步,但要保持标记相对于窗口的位置.

I'm using the Google Maps API. When I click on a map marker, I want the map to zoom in one step, but maintain the marker's position relative to the window.

这类似于使用鼠标滚轮进行缩放时:缩放是朝着当前光标位置进行的.

This is similar to when you use the mouse wheel to zoom: the zooming is towards the current cursor position.

map.setZoom()函数相对于地图中心缩放.这不是我想要的.

The map.setZoom() function zooms relative to the center of the map. This is not what I want.

找不到任何简单的解决方案,有人知道吗?

Can't find any simple solution to this, anyone has a clue?

推荐答案

这种工作方式,不是一种优雅的解决方案:

This kind of works, not an elegant solution:

function zoomInAtMarker(marker)
{
    var pos = marker.getPosition();
    var bounds = map.getBounds();
    map.setZoom(map.getZoom() + 1);
    var span = map.getBounds().toSpan();
    var s = pos.lat() - span.lat() * (pos.lat() - bounds.getSouthWest().lat()) / bounds.toSpan().lat();
    var w = pos.lng() - span.lng() * (pos.lng() - bounds.getSouthWest().lng()) / bounds.toSpan().lng();
    map.panToBounds({ south:s, north:s + span.lat(), west:w, east:w + span.lng()});
}

这篇关于Google地图放大标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆