【发布时间】:2021-07-15 09:19:22
【问题描述】:
尝试显示多个标记,但不起作用
(3) InvalidValueError: setTitle: not a string 和多个这些错误 InvalidValueError:setCenter:不是具有有限坐标的 LatLng 或 LatLngLiteral:在属性 lat:NaN 不是可接受的值
<script>
let cord = []
$(`.cord`).each(( i , el) => {
cord[i] = {
'latitude': Number($(el).data('latitude')),
'longitude': Number($(el).data('longitude')),
}
});
// Initialize and add the map
function initMap() {
let uluru;
uluru = { lat: -33, lng: 151 };
// The map, centered at Uluru
const map = new google.maps.Map(document.getElementById("map"), {
zoom: 4,
center: uluru,
});
var i = 0;
while(Object.values(cord).length>i){
// The marker, positioned at Uluru
const map = new google.maps.Map(document.getElementById("map"), {
zoom: 4,
center: uluru,
});
uluru = { lat: cord[i]['latitude'], lng: cord[i]['longitude'] };
const marker = new google.maps.Marker({
position: uluru,
map: map,
title: i,
});
i++;
} //loop
} //map
</script>
【问题讨论】:
-
请在一个问题中只提出一个问题,并提供一个 minimal reproducible example 来表明该问题。见How to Ask。
标签: javascript google-maps-api-3 google-maps-markers