I'm currently using Google Maps v3 API with their jQuery client. I'm trying to get the latitude and longitude from a mouse click on the map, concatenate them to a string and add the string to an input field on the page. Being quite new to jQuery, I'm completely lost. Can anyone 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});
});
$(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With