2016-10-01 20 views
-1

私は自分のウェブサイト用に作成している地図にピンを追加しようとしています。複数のピンGoogleマップ

htmlコードでは最大4個のピンしか得られませんが、これまでのところ6個を追加しようとしましたが、それ以上のことがあります。

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
    <title>Google Maps Multiple Markers</title> 
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCHLqk7ajEQviaeDoaEOiYvxWAtuATm5oY&callback=initMap"> 
      type="text/javascript"></script> 
</head> 
<body> 
    <div id="map" style="width: 600px; height: 600px;"></div> 

    <script type="text/javascript"> 
    var locations = [ 
     ['Stolford Beach Stogursey TA51TW', 51.207404, -3.099290, 1], 
     ['Lilstock Beach, Lillstock TA51SU', 51.201793, -3.186663, 2], 
     ['Kilve Beach, Kilve TA51EG', 51.192534, -3.227412, 3], 
     ['<p>East Quantoxhead Beach</p> <p>East Quantoxhead TA51EJ 5Mins- Accesible from kilve at low tide (14:30)</p>', 51.190542, -3.238637, 4], 
     ['St Andries Bay, West Quantoxhead TA4 4DY', 51.181029, -3.272607, 5] 
     ['Doniford Beach, Doniford TA230TL', 51.179679, -3.308254, 6] 
    ]; 

    var map = new google.maps.Map(document.getElementById('map'), { 
     zoom: 9, 
     center: new google.maps.LatLng(50.858026, -3.392425), 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

    var infowindow = new google.maps.InfoWindow(); 
maxWidth: 200 
    var marker, i; 

    for (i = 0; i < locations.length; i++) { 
     marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
     map: map 
     }); 

     google.maps.event.addListener(marker, 'click', (function(marker, i) { 
     return function() { 
      infowindow.setContent(locations[i][0]); 

      infowindow.open(map, marker); 

     } 
     })(marker, i)); 
    } 
    </script> 
</body> 
</html> 

答えて

0

var locationsを初期化する場所をよく見てください。 4番目の要素の後にネストされた配列の背後に,を忘れてしまった。

さらに、エラーの原因となるため、行番号6のURLから&callback=initMapを削除してください。

希望すると助かります!

関連する問題