gpt4 book ai didi

javascript - Google MarkerClusterer 不显示标记

转载 作者:行者123 更新时间:2023-11-30 16:49:12 26 4
gpt4 key购买 nike

我正在尝试用 this sample code 提供的数据替换我的数据,但我的代码不起作用。我刚刚添加了一个名为 results 的数组,并尝试将其 lat 和 lan 值传递给 map ,但由于某些原因它不起作用。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>MarkerClusterer v3 Simple Example</title>
<style >
body {
margin: 0;
padding: 10px 20px 20px;
font-family: Arial;
font-size: 16px;
}
#map-container {
padding: 6px;
border-width: 1px;
border-style: solid;
border-color: #ccc #ccc #999 #ccc;
-webkit-box-shadow: rgba(64, 64, 64, 0.5) 0 2px 5px;
-moz-box-shadow: rgba(64, 64, 64, 0.5) 0 2px 5px;
box-shadow: rgba(64, 64, 64, 0.1) 0 2px 5px;
width: 600px;
}
#map {
width: 600px;
height: 400px;
}
</style>

<script src="https://maps.googleapis.com/maps/api/js"></script>
<script>
var script = '<script type="text/javascript" src="https://googlemaps.github.io/js-marker-clusterer/src/markerclusterer';
if (document.location.search.indexOf('compiled') !== -1) {
script += '_compiled';
}
script += '.js"><' + '/script>';
document.write(script);
</script>

<script>
function initialize() {

var results = [
[
'Alexs loc', '37.9908372',
'23.7383394', '0',
'id-90'], [
'John Jamess loc', '37.9908372',
'23.7383394', '1',
'id-89'], [
'Normans loc', '38.075352',
'23.807885', '3',
'id-12'], [
'Jack Moores loc', '37.9908372',
'23.7383394', '2',
'id-67'], ];
var center = new google.maps.LatLng(37.9908372, 23.7383394);

var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var markers = [];
for (var i = 0; i < results.length; i++) {
var placeLoc = new google.maps.LatLng(results[i][1], results[i][2]);
var marker = new google.maps.Marker({
position: latLng
});
markers.push(marker);
}
var markerCluster = new MarkerClusterer(map, markers);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<p>
<a href="?compiled">Compiled</a> |
<a href="?">Standard</a> version of the script.
</p>
<div id="map-container"><div id="map"></div></div>
</body>
</html>

最佳答案

未检查,但我看到您在循环中创建标记的代码。这里的position应该是指placeLoc而不是latLng

var marker = new google.maps.Marker({
position: placeLoc
});

关于javascript - Google MarkerClusterer 不显示标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30772408/

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