gpt4 book ai didi

javascript - 谷歌地图API错误: initMap is not a function

转载 作者:行者123 更新时间:2023-12-03 03:43:43 24 4
gpt4 key购买 nike

我的 Google map 标记出现问题。它们仍然有效,但我在开发控制台中得到以下输出:

maps.php:43 Uncaught SyntaxError: Unexpected token ,

这是我的代码中的这一行:

center: {lat: <?php echo $e[0]; ?>, lng: <?php echo $e[1]; ?>}

下一条错误消息是:

message
:
"initMap is not a function"
name
:
"InvalidValueError"
stack
:
"Error↵ at new mc (https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=initMap:47:499)↵ at Object._.nc (https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=initMap:48:96)↵ at $g (https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=initMap:98:420)↵ at https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=initMap:138:53↵ at Object.google.maps.Load (https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=initMap:21:5)↵ at https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=initMap:137:20↵ at https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=initMap:138:68

我没有收到我犯的错误,这是我的 JS 代码:

<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: {lat: <?php echo $e[0]; ?>, lng: <?php echo $e[1]; ?>}
});

// Create an array of alphabetical characters used to label the markers.

// Add some markers to the map.
// Note: The code uses the JavaScript Array.prototype.map() method to
// create an array of markers based on a given "locations" array.
// The map() method here has nothing to do with the Google Maps API.

var infoWin = new google.maps.InfoWindow();

var markers = locations.map(function (location, i) {

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

google.maps.event.addListener(marker, 'click', function (evt) {
infoWin.setContent("<div style='color: black;'><p style='font-size:1.5em;'>"+ location.date +"</p><h2>" + location.headline + "</h2><h3>" + location.subheadline + "</h3><p style='font-size:1.2em;'><strong>Start:</strong> "+ location.start +" Uhr</br><strong>Ende:</strong> "+ location.end +" Uhr</p><hr><p>" + location.text + "</p><hr><p style='font-size: 1.2em;'><strong>Adresse:</strong></br>" + location.street + " " + location.streetnr + ", " + location.plz + " " + location.city + "\n\
</p><a style='font-size: 1.2em;' target='blank_' href='http://www.google.com/maps/place/" + location.lat + "," + location.lng + "'>Routenführung</a></div>");
infoWin.open(map, marker);
})

return marker;

});

console.log(markers);

// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers,
{imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
}
var locations = <?php echo json_encode($r); ?>
console.log(locations);

</script>

问题是我有 56 个标记,但只显示了 27 个。我觉得可能是数据有问题。它可以?我搜索过但没有发现像我这样的类似问题。

最佳答案

解析时出现数据错误。某些数据未设置 Lat 或 Lng ...

关于javascript - 谷歌地图API错误: initMap is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45505790/

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