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 pletely 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});
});
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 pletely 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});
});
Share
Improve this question
edited Jul 24, 2012 at 14:57
The Alpha
146k29 gold badges293 silver badges311 bronze badges
asked Jul 24, 2012 at 13:28
Richard StokesRichard Stokes
3,5528 gold badges44 silver badges57 bronze badges
1 Answer
Reset to default 7$(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.