将Google地图上的平移点指向屏幕上的特定像素位置(API v3) [英] Pan point on Google Map to specific pixel position on screen (API v3)

查看:453
本文介绍了将Google地图上的平移点指向屏幕上的特定像素位置(API v3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

overlay 是Google地图叠加层, offsetx时,offsety 是地图中心的像素距离,I想要平铺 latlong ,以下工作。

When overlay is a Google maps overlay and offsetx, offsety is the pixel distance from the maps center that I want to pan latlong to, the following works.

var projection = overlay.getProjection();
var pxlocation = projection.fromLatLngToContainerPixel(latlong);
map.panTo(projection.fromContainerPixelToLatLng(new google.maps.Point(pxlocation.x+offsetx,pxlocation.y+offsety)));

然而,我并不总是在地图上覆盖和地图.getProjection()返回一个投影,而不是 MapCanvasProjection ,它没有方法我需要。

However, I don't always have an overlay on the map and map.getProjection() returns a projection, not a MapCanvasProjection which does not have the methods I need.

有没有一种方法可以做到这一点,而不必为它重叠覆盖?

Is there a way to do this without making an overlay specificaly for it?

推荐答案

由于没有人提出更好的方法,这是我的解决方案。为给我一个 MapCanvasProjection 对象的唯一工作做一个覆盖。

Since nobody has come up with a better way, here's my solution. Make an overlay with the sole job of giving me a MapCanvasProjection object.

var helper = new google.maps.OverlayView();
helper.setMap(map);
helper.draw = function () { 
    if (!this.ready) { 
        this.ready = true; 
        google.maps.event.trigger(this, 'ready'); 
    } 
}; 
var projection = helper.getProjection();
...

希望这有助于某人。更好的建议欢迎。

Hope this helps someone. Better suggestions welcome.

这篇关于将Google地图上的平移点指向屏幕上的特定像素位置(API v3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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