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