是否可以将地图居中放置在固定位置 (lat lng) - 100px? [英] Is it possible to center a map at a fixed position (lat lng) - 100px?

查看:19
本文介绍了是否可以将地图居中放置在固定位置 (lat lng) - 100px?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是,我想将地图居中到一个固定位置:

map.setCenter(markerCliccato.getPosition());

和更少(Y 轴)向下 100 像素.是否可以?或者我需要这个虚拟"点的纬度/经度?

这是因为我有一个非常高的InfoWindow,我需要把它放在离地图顶部100px的地方!不能在信息窗口上使用margin",因为这可能会给地图中的其他标记带来麻烦.

示例

我认为这一点是纬度/经度:

使用 FF 15、IE 9 和 Chrome 21 进行测试

I mean, I'd like to center a map to a fixed position :

map.setCenter(markerCliccato.getPosition());

and less (Y-axis) 100px down. Is it possible? Or I need the Lat/Lng of this "virtual" point?

This is because I have a InfoWindow very height, and I need to put it 100px from top of the map! Can't use "margin" on infowindow because can make troubles with other marker in the map.

Example

I have this point as Lat/Lng : https://maps.google.com/?q=54.572062,-3.038818

But I want to center the map at https://maps.google.com/?q=54.486793,-3.042046 (which is more or less 100px down of my point, in the map)

解决方案

ok, i need to post pictures :)

this is before the click

and this is after

there is no gray area, the map is all rendered.

also, to see the marker you must allow the site to track your location.

function offsetCenter(latlng, offsetx, offsety) {
    var scale = Math.pow(2, map.getZoom());
    var nw = new google.maps.LatLng(
    map.getBounds().getNorthEast().lat(), map.getBounds().getSouthWest().lng());

    var worldCoordinateCenter = map.getProjection().fromLatLngToPoint(latlng);
    var pixelOffset = new google.maps.Point((offsetx / scale) || 0, (offsety / scale) || 0)

    var worldCoordinateNewCenter = new google.maps.Point(
    worldCoordinateCenter.x - pixelOffset.x, worldCoordinateCenter.y + pixelOffset.y);

    var newCenter = map.getProjection().fromPointToLatLng(worldCoordinateNewCenter);

    map.setCenter(newCenter);
}

see it working here: http://jsfiddle.net/RASG/vA4eQ/

tested with FF 15, IE 9 and Chrome 21

这篇关于是否可以将地图居中放置在固定位置 (lat lng) - 100px?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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