Google Map jQuery - getting LatLng with the mouse

I am currently using the Google Maps API v3 with my jQuery client . I am trying to get the latitude and longitude with the mouse on the map, combine them into a line and add the line to the input field on the page. Being completely new to jQuery, I am completely lost. Can someone point me in the right direction? My code that initializes the Google map on my page is as follows:

$(document).ready(function() { var yourStartLatLng = new google.maps.LatLng(53.307697, -6.222317); $('#map-canvas').gmap({'center': yourStartLatLng, zoom: 15}); }); 
+6
source share
1 answer
 $(document).ready(function() { var yourStartLatLng = new google.maps.LatLng(53.307697, -6.222317); $('#map_canvas').gmap({'center': yourStartLatLng, zoom: 15}) .bind('init', function(event, map) { $(map).click( function(event) { var lat=event.latLng.lat(); var lng=event.latLng.lng(); $('#latlng').val(lat+', '+lng); // 'latlng' is the id of the input }); }); }); 

Demo.

+7
source

Source: https://habr.com/ru/post/921205/


All Articles