Mantar
Mantar

Reputation: 2720

Finding a Google Markers location on page?

Simple situation: Marker on map, want to put a DIV next to it that displays on mouse over.

But how on earth do I get the markers current placement for the DIV?

LatLng won't exactly get me anywhere..

Upvotes: 0

Views: 193

Answers (1)

herostwist
herostwist

Reputation: 3968

This will get position of marker in pixels:

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)
);

Upvotes: 1

Related Questions