0
如何获取用户通过js点击地图的位置?谷歌地图添加位置
如何获取用户通过js点击地图的位置?谷歌地图添加位置
这里是我使用的地图画布上滴事件一次的回调函数:这样
function placeDroppedMarker()
{
var locale = new google.maps.LatLng(mouseLat, mouseLng);
document.getElementById('map-lat').value = mouseLat;
document.getElementById('map-lng').value = mouseLng;
document.getElementById('map-icon-input').value = SelectedIcon;
var marker = new google.maps.Marker({
position: locale,
map: map,
draggable: true
});
var image = new google.maps.MarkerImage(
"http://www.twulogin.org/ourride/wp-content/themes/spectrum/images/" + SelectedIcon + ".png",
new google.maps.Size(37,37),
new google.maps.Point(0,0),
new google.maps.Point(16,37),
new google.maps.Size(37,37)
);
marker.setIcon(image);
map.setCenter(locale);
}
你必须设置一个事件侦听器(在您的地图初始化函数)来获取mouseLat和mouseLng:
google.maps.event.addListener(map, 'mousemove', function(event) {
mouseLat = event.latLng.lat();
mouseLng = event.latLng.lng();
});
哪里地图是你的谷歌地图。
完整的工作示例是: http://www.ourride.org/?page_id=238
真棒,谢谢! – wnoveno 2010-08-25 17:57:23
(随时'接受'/'投票') – KeatsKelleher 2010-08-25 18:12:01