Google지도 API에 내장 옵션이 있거나이 기능을 구현하는 간단한 방법이 있습니까? 지도에서 한 지점을 두 번 클릭하고 Google지도에서 내 마커를 그 지점으로 옮기고 싶습니다.Google지도 API - 마커를 이동하려면지도에서 두 번 클릭하십시오.
답변
(편집 :.. Vinks '포스트 보면 그는 구글지도를 지적하고있는 disableDoubleClickZoom 옵션을)
물론
<!DOCTYPE html>
<html>
<head>
<title>Double click on the map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 500px;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
<script>
function initialize() {
var my_position = new google.maps.LatLng(50.5, 4.5);
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: my_position,
zoom: 15
});
var marker = new google.maps.Marker({
position: my_position,
map: map
});
// double click event
google.maps.event.addListener(map, 'dblclick', function(e) {
var positionDoubleclick = e.latLng;
marker.setPosition(positionDoubleclick);
// if you don't do this, the map will zoom in
e.stopPropagation();
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
<p>Double click on the map</p>
</body>
</html>
나는 엠마뉴엘 지연 대답을 언급하지만, 해결하기 위해 수 없습니다 stopPropagation 문제인 경우 Maps API의 disableDoubleClick 옵션을 사용해야합니다.
<!DOCTYPE html>
<html>
<head>
<title>Double click on the map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 500px;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
<script>
function initialize() {
var my_position = new google.maps.LatLng(50.5, 4.5);
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: my_position,
disableDoubleClickZoom: true,
zoom: 15
});
var marker = new google.maps.Marker({
position: my_position,
map: map
});
// double click event
google.maps.event.addListener(map, 'dblclick', function(e) {
var positionDoubleclick = e.latLng;
marker.setPosition(positionDoubleclick);
// if you don't do this, the map will zoom in
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
오 예, 그게 훨씬 낫습니다. 감사; 내가 기억할 것입니다 –
문제 없습니다. 방금 답변을 사용하여 문제가 발생했습니다. 경우에 따라 길게 터치하면 "dblclick"에 해당하는 것을 알고 있습니까? 더블 탭은 그렇게하기 쉽지 않기 때문에 모바일 장치에 유용 할 것입니다. – Vinks
http://touchpunch.furf.com/을 사용해보세요. 아마도 도움이됩니다. –
감사합니다 :
여기에 업데이트 된 결과입니다! 그건 속임수 야. –
효과가있었습니다. 하지만 콘솔 (파이어 폭스)'TypeError : e.stopPropagation은 함수가 아닙니다. ' 문제가 어디에 있습니까? –