Search code examples
google-maps-api-3jquery-ui-map

How to get latitude and longitude on click event with jquery-ui-map


When using 'Google maps v3 plugin for jQuery and jQuery Mobile', how to retrieve the latitude and longitude values under the mouse pointer when clicked on the map?


Solution

  • Even though the click event listener is already added to the map inside the plugin, the event object returned, does not give the latLng value. Adding the click event listener to the map object from my code, worked for me (found the solution by referring this answer).

    var map = $('#map_canvas').gmap('get', 'map');
    $(map).addEventListener('click', function(event) {
        alert(event.latLng);
    });