在页面上查找Google Markers位置?

时间:2011-05-04 12:13:23

标签: javascript google-maps

简单的情况: 地图上的标记, 想要在鼠标悬停时显示旁边的DIV。

但是我如何才能获得DIV当前位置的标记?

LatLng不会让我到任何地方......

1 个答案:

答案 0 :(得分:1)

这将获得标记的位置,以像素为单位:

var scale = Math.pow(2, map.getZoom())
, nw = new google.maps.LatLng(
    map.getBounds().getNorthEast().lat(),
    map.getBounds().getSouthWest().lng()
)
, worldCoordinateNW = map.getProjection().fromLatLngToPoint(nw)
, worldCoordinate = map.getProjection().fromLatLngToPoint(marker.getPosition())
, pixelOffset = new google.maps.Point(
    Math.floor((worldCoordinate.x - worldCoordinateNW.x) * scale),
    Math.floor((worldCoordinate.y - worldCoordinateNW.y) * scale)
);