4

我仍然有谷歌地图初始化的问题。我也看不到所有插入的标记。我声明我不懂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>

任何形式的帮助表示赞赏。

谢谢

4

1 回答 1

4

那是因为您正在向不存在的函数添加事件侦听器 ( initialize)。你的函数被调用initializeMaps所以改变google.maps.event.addDomListener(window, 'load', initialize);google.maps.event.addDomListener(window, 'load', initializeMaps);

于 2013-10-15T21:34:44.320 回答