gpt4 book ai didi

google-maps - “Uncaught reference error: initialize is not defined”

转载 作者:行者123 更新时间:2023-12-02 11:20:57 61 4
gpt4 key购买 nike

我仍然遇到谷歌地图初始化问题。我也看不到插入的所有标记。我声明我不懂javascript,我发现很难理解我错在哪里。我带着自己的问题查看了几篇帖子,但没有成功找到问题的解决方案。

这是我的文件 googlemap.js

var markers = [
['<b style="color:red;"></b></br> Main Office - Malta', 35.895079, 14.49011],
['<b style="color:red;"></br> Desk Office - Principaute de Monaco', 43.75042,7.438238],
['<b style="color:red;"></b></br> Desk Office - Belgium', 50.50389, 4.46994],
['<b style="color:red;"></b></br> Desk Office - Cyprus', 35.038174, 33.40443],
['<b style="color:red;"></b></br> Desk Office - Hong-Kong', 22.354694, 114.131719],
['<b style="color:red;"></b></br> Desk Office - Jersey', 40.727865, -74.078228],
['<b style="color:red;"></b></br> Desk Office - The Netherlands', 52.106505,5.515137],
['<b style="color:red;"></b></br> Desk Office - Russia & CIS', 55.719648, 37.567421],
['<b style="color:red;"></b></br> Desk Office - United Kingdom', 52.509535,-0.791016],
['<b style="color:red;"></b></br> Desk Office - China', 34.412677, 103.954634],
['<b style="color:red;"></b></br> Desk Office - Guernsey', 40.725812,-73.954167],
['<b style="color:red;"></b></br> Desk Office - Ireland', 40.737158, -73.886638],
['<b style="color:red;"></b></br> Desk Office - Luxembourg', 49.614561,6.132495],
['<b style="color:red;"></b></br> Desk Office - Mauritius', -20.286556, 57.504439],
['<b style="color:red;"></b></br> Desk Office - New-York', 40.729379, -74.003781],
['<b style="color:red;"></b></br> Desk Office - Singapore', 1.283094,103.8439]

];

function initializeMaps() {
var latlng = new google.maps.LatLng(35.895079, 14.49011);
var myOptions = {
zoom: 15,
center: latlng,
navigationControl: false,
navigationControlOptions: {style: google.maps.NavigationControlStyle.NORMAL},
streetViewControl: false,
//
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.TOP_LEFT
},
mapTypeControl: true,
navigationControl: false,
mapTypeControlOptions: {

position: google.maps.ControlPosition.TOP_RIGHT, style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
mapTypeIds: [google.maps.MapTypeId.TERRAIN, google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, "blackMap"]

},


};


var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

//Bl map style


var styleBl =
[


{
"featureType": "water",
"stylers": [
{ "saturation": -21 },
{ "hue": "#00e5ff" },
{ "lightness": 21 }
]


},{
"featureType": "landscape",
"stylers": [
{ "hue": "#1f78c4" }
]


},{
"featureType": "road",
"elementType": "labels.text",
"stylers": [
{ "visibility": "on" },
{ "color": "#354a82" }
]

},{
},{
"featureType": "poi.business" }
]

var styledMapOptions = {name: "Bl"}


var blMapType = new google.maps.StyledMapType(styleBwl, styledMapOptions);


map.mapTypes.set("blackMap", blMapType);

map.setMapTypeId("blackMap");
var infowindow = new google.maps.InfoWindow();

var marker, i;
var bounds = new google.maps.LatLngBounds();


for (i = 0; i < markers.length; i++) {
var pos = new google.maps.LatLng(markers[i][1], markers[i][2]);
bounds.extend(pos);
marker = new google.maps.Marker({
position: pos,
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(markers[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
map.fitBounds(bounds);
}
google.maps.event.addDomListener(window, 'load', initialize);

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

感谢任何形式的帮助。

谢谢

最佳答案

这是因为您要向不存在的函数添加事件监听器 (initialize)。您的函数名为 initializeMaps,因此将 google.maps.event.addDomListener(window, 'load',initialize); 更改为 google.maps.event.addDomListener (窗口,“加载”,initializeMaps);

关于google-maps - “Uncaught reference error: initialize is not defined”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19391449/

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