gpt4 book ai didi

javascript - Google map 中的自定义标记和航路点标记

转载 作者:行者123 更新时间:2023-11-29 16:13:05 25 4
gpt4 key购买 nike

我正在寻求帮助。我有下面的谷歌地图代码,工作正常。我唯一需要的是起点上的自定义标记:(51.943382, 6.463116) 并且航点上没有标记。这可以做到吗?我已经尝试了几个来自 Stackoverflow 的解决方案,但我对 GM 代码和编程技能的理解不足以得到我想要的东西。谢谢!

<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Directions Waypoints</title>

<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer({
});


var myOptions = {
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP,
}


map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
calcRoute();
}

function calcRoute() {

var waypts = [];


stop = new google.maps.LatLng(51.943571, 6.463856)
waypts.push({
location:stop,
stopover:true});
stop = new google.maps.LatLng(51.945032, 6.465776)
waypts.push({
location:stop,
stopover:true});
stop = new google.maps.LatLng(51.945538, 6.469413)
waypts.push({
location:stop,
stopover:true});
stop = new google.maps.LatLng(51.947462, 6.467941)
waypts.push({
location:stop,
stopover:true});
stop = new google.maps.LatLng(51.945409, 6.465562)
waypts.push({
location:stop,
stopover:true});
stop = new google.maps.LatLng(51.943700, 6.462096)
waypts.push({
location:stop,
stopover:true});

start = new google.maps.LatLng(51.943382, 6.463116);
end = new google.maps.LatLng(51.943382, 6.463116);

var request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.DirectionsTravelMode.WALKING
};

directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var route = response.routes[0];

}
});
}
</script>
</head>
<body onLoad="initialize()">
<div id="map_canvas" style="width:70%;height:80%;"></div>
</body>
</html>

最佳答案

我认为只有一种解决方案可以实现这一目标。使用以下代码删除所有标记:

directionsDisplay = new google.maps.DirectionsRenderer({
suppressMarkers: true
});

并在您的起点手动添加标记。

这是一个 JSFiddle 来说明。

希望这对您有所帮助!

关于javascript - Google map 中的自定义标记和航路点标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22639178/

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