gpt4 book ai didi

google-maps - Google Maps API - 双击 map 上的点以将标记移动到那里

转载 作者:行者123 更新时间:2023-12-02 17:36:05 24 4
gpt4 key购买 nike

google maps API 中是否有内置选项或实现此功能的简单方法。我想双击 map 上的一个点,让谷歌地图将我的标记移动到那个点。

最佳答案

(编辑:查看 Vinks 的帖子。他指出 Google map 有一个 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>

关于google-maps - Google Maps API - 双击 map 上的点以将标记移动到那里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26787022/

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