I want to find out the x and y coordinates of a click event on Google Map. This X and Y coordinates should be with respect to screen or page.
Asked
Active
Viewed 307 times
-2
-
1I mean, if you need a coordinate in respect to the window (or screen) than you having a Goog map, or a hot potato, makes no difference. – Roko C. Buljan Apr 10 '15 at 01:47
-
Here is a link how to get coordinates - http://stackoverflow.com/questions/55677/how-do-i-get-the-coordinates-of-a-mouse-click-on-a-canvas-element. As Roko mentioned Google Maps are not related to it. – Stephen L. Apr 10 '15 at 01:54
-
yes the map is 100% x 100% , and i just want to get the coordinate of the point of click on google map and yes it should be with respect to screen. My code is little complex and its difficult to put the whole set to codes. Thanks for the reply man @RokoC.Buljan – Sumit Sagar Apr 10 '15 at 02:05
-
@SumitSagar well, have you tested my example? – Roko C. Buljan Apr 10 '15 at 02:08
1 Answers
0
mapCanvas.addEventListener("click", function(e){
var r = this.getBoundingClientRect();
var x = e.clientX - r.left;
var y = e.clientY - r.top;
console.log(x, y);
});

Roko C. Buljan
- 196,159
- 39
- 305
- 313