Kokila
Kokila

Reputation: 1007

How to get x,y coordinates on clicking on Google maps

I want x,y coordinates for the pixel which I click on the google maps using jquery.. How to get it? I can only get the Latitude and longitude values.. But I need left, top positions..

Could anyone please help?

Upvotes: 0

Views: 2474

Answers (2)

Kokila
Kokila

Reputation: 1007

Click event's PageX, PageY will give the left, top position.

$('#map-canvas').click(function(event) {
        $("#tooltip").css('left', event.pageX);
        $("#tooltip").css('top',event.pageY);
});

Refer this

Upvotes: 0

CWSpear
CWSpear

Reputation: 3270

Try using a click event on the container and the event will have an offsetX and offsetY on it that are coordinates relative to the container.

See this fiddle:

http://jsfiddle.net/N66hh/2/

Upvotes: 1

Related Questions