admin管理员组文章数量:1334704
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.
本文标签: javascriptGoogle Map jQuerygetting LatLng from mouse clickStack Overflow
版权声明:本文标题:javascript - Google Map jQuery - getting LatLng from mouse click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742367225a2461531.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论