gpt4 book ai didi

javascript - JS 中带有传单的地理位置

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

以下 JS 脚本(为了完整性而包含 CSS/HTML)旨在打开传单 map 图 block 并标记用户位置。当它打开 map 时,它不会标记用户位置。为什么不呢?

<!DOCTYPE html>
<html>
<head>
<title>Leaflet GeoLocation</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<style>
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map').setView([43, -79], 18);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
maxZoom: 18
}).addTo(map);
var newMarker = new L.marker(e.latlng).addTo(map);
</script>
</body>
</html>

最佳答案

您不会尝试在此代码中的任何位置获取用户位置。这一行:

var newMarker = new L.marker(e.latlng).addTo(map);
您提供的代码中未定义

e。所以你需要给它一个纬度/经度值。

关于javascript - JS 中带有传单的地理位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38424051/

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