Get X,Y of mouse click on map

1,111 views
Skip to first unread message

IanR

unread,
Aug 11, 2009, 2:24:31 PM8/11/09
to Google Maps JavaScript API v3
Is there a way to get the X,Y coordinates in pixels when the users
clicks on the map? I know you can just setup a simple event listening
in javascript and do something like window.event.clientX.

Esa

unread,
Aug 11, 2009, 9:54:12 PM8/11/09
to Google Maps JavaScript API v3


google.maps.event.addListener(map, 'click', function(event){
var X = event.pixel.x;
var Y = event.pixel.y;
}

IanR

unread,
Aug 12, 2009, 8:56:00 AM8/12/09
to Google Maps JavaScript API v3
This worked great.

Is it possible to get this same event object from a marker click
event?

I tried to do

google.maps.event.addListener(marker, 'click', function(event){}

but didn't have any luck.

I basically want to get the X,Y in pixels of the mouse click when the
user clicks on a marker.

Esa

unread,
Aug 12, 2009, 9:41:10 AM8/12/09
to Google Maps JavaScript API v3


On Aug 12, 3:56 pm, IanR <ianrear...@gmail.com> wrote:

> Is it possible to get this same event object from a marker click
> event?

No. Marker events do not return anything.

> I basically want to get the X,Y in pixels of the mouse click when the
> user clicks on a marker.

It is very complicated in v3. Start by examining Nianwei's source
code:
http://google-maps-utility-library-v3.googlecode.com/svn/tags/keydragzoom/1.0/

Ian Reardon

unread,
Aug 12, 2009, 10:32:58 AM8/12/09
to google-map...@googlegroups.com
Do you have any idea if this is a feature that might get added in the future?

Esa

unread,
Aug 12, 2009, 2:57:20 PM8/12/09
to Google Maps JavaScript API v3


On Aug 12, 5:32 pm, Ian Reardon <ianrear...@gmail.com> wrote:
> Do you have any idea if this is a feature that might get added in the
> future?

No idea but this been asked by a couple of people. Issue tracker is
the official forum which
Google people read and give some answers.

I was surprised to find only a single star (before mine) in the
feature request posted by Björn
http://code.google.com/p/gmaps-api-issues/issues/detail?id=1523
Reply all
Reply to author
Forward
0 new messages