gpt4 book ai didi

javascript - 使用 Leaflet Routing Machine 在两个标记之间找到路径

转载 作者:行者123 更新时间:2023-12-04 11:46:54 25 4
gpt4 key购买 nike

我正在尝试使用传单在我的 map 上的标记之间找到一条路线。
我使用了该代码:

L.Routing.control({
waypoints: [
L.latLng(36.9009882, 10.3009531),
L.latLng(36.9922751, 10.1255164)
]}).addTo(map);

但我的 map 上没有新的东西。
有什么遗漏吗?我应该怎么办?

最佳答案

1 - 您是否将(传单路由机)包含在您的应用程序中?
2-确保你的 map 变量是( map )试试这个简单的例子
欲了解更多信息,请访问此页面
https://www.liedman.net/leaflet-routing-machine/

    var mymap = L.map('mapid').setView([51.505, -0.09], 5);

L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, ' +
'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
id: 'mapbox/streets-v11',
tileSize: 512,
zoomOffset: -1
}).addTo(mymap);

L.marker([51.5, -0.09]).addTo(mymap)
.bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup();

L.marker([53.5, -0.09]).addTo(mymap)
.bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup();


// route the way leafet machine as I said AI


L.Routing.control({
waypoints: [
L.latLng(51.5, -0.09),
L.latLng(53.5, -0.09)
]
}).addTo(mymap);
<!DOCTYPE html>
<html>
<head>

<title>Quick Start - Leaflet</title>

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />

<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" crossorigin=""></script>

<link rel="stylesheet" href="https://unpkg.com/leaflet@1.2.0/dist/leaflet.css" />
<link rel="stylesheet" href="https://unpkg.com/leaflet-routing-machine@latest/dist/leaflet-routing-machine.css" />
<script src="https://unpkg.com/leaflet@1.2.0/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-routing-machine@latest/dist/leaflet-routing-machine.js"></script>

</head>
<body>



<div id="mapid" style="width: 600px; height: 400px;"></div>
<script>





</script>



</body>
</html>

关于javascript - 使用 Leaflet Routing Machine 在两个标记之间找到路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38503832/

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