How to get latitude and longitude in click event using jquery-ui-map

When using the Google maps v3 plugin for jQuery and jQuery Mobile, how do I get the latitude and longitude values ​​under the mouse pointer when I click on the map?

+3
source share
3 answers

Even though the click event listener has already been added to the map inside the plugin, the returned event object does not give a latLng value. Adding a click event listener to a map object from my code worked for me (a solution was found by contacting this ).

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

Johansalllarsson's solution works fine for me, so here is my sample code:

<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=true" type="text/javascript"></script>
<script src="js/jquery.ui.map.full.min.js" type="text/javascript"></script> 
<script type="text/javascript">
$(function() {
    $('#map').gmap();
    $($('#map').gmap('get', 'map')).dblclick(function(event) {
        alert(event.latLng);
    });
});
</script>
+2
source
$($('#map_canvas').gmap('get', 'map')).click(function(event) {
    console.log(event.latLng);
});

. http://jquery-ui-map.googlecode.com/svn/trunk/demos/jquery-google-maps-geocoding.html

+1
source

All Articles