是否有可能将地图定位在固定位置(经纬度) - 100px? [英] Is it possible to center a map at a fixed position (lat lng) - 100px?

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

问题描述

我的意思是,我想将地图置于固定位置:

  map.setCenter(markerCliccato.getPosition ()); 

及更少(Y轴)100px向下。可能吗?或者我需要这个虚拟点的纬度/经度?



这是因为我有一个InfoWindow的高度,我需要把它放在顶部100px地图!不能在infowindow上使用margin,因为它可能会使地图中的其他标记产生问题。



示例



我将这一点作为Lat / Lng:



经过测试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

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

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