[英]Move marker on click
我正在創建一個傳單地圖,我想通過 1)拖動和 2)鼠標單擊來移動標記。 'dragend'
或鼠標點擊的坐標被寫入 'latitude' 和 'longitude'。 阻力一切都很好,但我正在努力解決 onclick。
總體目標是讓 map 更適合智能手機用戶。
如果您在單擊標記時想要 lalng,請使用以下命令:
marker.on('dragend click', function (e) {
document.getElementById('latitude').value = marker.getLatLng().lat;
document.getElementById('longitude').value = marker.getLatLng().lng;
});
如果您在單擊 map 時想要標記的緯度:
map.on('click', function (e) {
document.getElementById('latitude').value = marker.getLatLng().lat;
document.getElementById('longitude').value = marker.getLatLng().lng;
});
如果你想要你點擊的 map 的latlng:
map.on('click', function (e) {
document.getElementById('latitude').value = e.latlng.lat;
document.getElementById('longitude').value = e.latlng.lng;
});
您的代碼沒有像拖動代碼這樣的鼠標單擊事件代碼。
marker.on('dragend', function (e) {
document.getElementById('latitude').value = marker.getLatLng().lat;
document.getElementById('longitude').value = marker.getLatLng().lng;
//Confirmit.page.getQuestion('R3QX_pin_lat').setValue(marker.getLatLng().lat);
//Confirmit.page.getQuestion('R3QX_pin_lng').setValue(marker.getLatLng().lng);
});
您可以編寫類似於拖動代碼的鼠標單擊代碼
map.on('click', function (e) {
document.getElementById('latitude').value = marker.getLatLng().lat;
document.getElementById('longitude').value = marker.getLatLng().lng;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.