如何以像素为单位偏移Google地图(API v3)的中心? [英] How to offset the center of a Google maps (API v3) in pixels?
本文介绍了如何以像素为单位偏移Google地图(API v3)的中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以在Google maps api v3中抵消地图的中心。我想在像素中控制此偏移量,因为lat和lng似乎是错误的并且很难预测。
I was wondering if it is possible to offset the center of a map in Google maps api v3. I would like to control this offset in pixels, since by lat and lng seems wrong and very difficult to predict.
我只需放置一个标记,然后将中心偏移250px,这样我就可以在地图中间放置其他内容。
I just need to place a marker, and then offset the center by 250px so I can place some other content in the middle of the map.
希望有人能帮助!
推荐答案
发现这个问题时,研究和思想,我应该提供答案:
$ b
Found this question when researching and thought I should provide an answer:
function map_recenter(latlng,offsetx,offsety) {
var point1 = map.getProjection().fromLatLngToPoint(
(latlng instanceof google.maps.LatLng) ? latlng : map.getCenter()
);
var point2 = new google.maps.Point(
( (typeof(offsetx) == 'number' ? offsetx : 0) / Math.pow(2, map.getZoom()) ) || 0,
( (typeof(offsety) == 'number' ? offsety : 0) / Math.pow(2, map.getZoom()) ) || 0
);
map.setCenter(map.getProjection().fromPointToLatLng(new google.maps.Point(
point1.x - point2.x,
point1.y + point2.y
)));
}
/ code>使用以下调用函数引用:
If your Google maps variable isn't map
use the following call function reference:
function map_recenter(map,latlng,offsetx,offsety) { ...
这篇关于如何以像素为单位偏移Google地图(API v3)的中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文