gpt4 book ai didi

javascript - Google Map jQuery - 从鼠标点击获取 LatLng

转载 作者:数据小太阳 更新时间:2023-10-29 05:16:25 25 4
gpt4 key购买 nike

我目前正在通过 their jQuery client 使用 Google Maps v3 API .我试图通过在 map 上单击鼠标来获取纬度和经度,将它们连接到一个字符串并将该字符串添加到页面上的输入字段中。作为 jQuery 的新手,我完全迷路了。谁能指出我正确的方向?我在我的页面上初始化 Google map 的代码如下:

$(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.

关于javascript - Google Map jQuery - 从鼠标点击获取 LatLng,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11631922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com