-1

Having a problem loading a map. it works when I delete some of these, using it as a prototype, will then be improving it more, but want a working map first. If I delete some of the variables in places it works.

var places = [];

places.push(new google.maps.LatLng(51.5620199,0.1482561));
places.push(new google.maps.LatLng(51.5339503,0.0952273));
places.push(new google.maps.LatLng(51.5508891,0.1441977));
places.push(new google.maps.LatLng(51.5314549,0.1516036));
places.push(new google.maps.LatLng(51.5403587,0.1613397));
places.push(new google.maps.LatLng(51.5393216,0.0910468));
places.push(new google.maps.LatLng(51.5387988,0.1375149));
places.push(new google.maps.LatLng(51.5267108,0.1192737));
places.push(new google.maps.LatLng(51.5439753,0.1133839));
places.push(new google.maps.LatLng(51.5439188,0.0757538));
places.push(new google.maps.LatLng(51.5322426,0.1468971));
places.push(new google.maps.LatLng(51.5550092,0.1401791));
places.push(new google.maps.LatLng(51.5399895,0.1657495));
places.push(new google.maps.LatLng(51.5341989,0.0863277));
places.push(new google.maps.LatLng(51.5515427,0.1295441));
places.push(new google.maps.LatLng(51.6409351,-0.0032547));
places.push(new google.maps.LatLng(51.6279264,0.0065626));
places.push(new google.maps.LatLng(51.6165614,-0.0072571));
places.push(new google.maps.LatLng(51.6328802,0.0039923));
places.push(new google.maps.LatLng(51.6311623,0.0034831));
places.push(new google.maps.LatLng(51.619693,-0.0169432));
places.push(new google.maps.LatLng(51.6226259,0.0009978));
places.push(new google.maps.LatLng(51.6166878,0.0001155));
places.push(new google.maps.LatLng(51.5090544,-0.0008842));
places.push(new google.maps.LatLng(51.5002995,-0.021799));
places.push(new google.maps.LatLng(51.5703348,-0.071546));
places.push(new google.maps.LatLng(51.5482429,-0.0548263));
places.push(new google.maps.LatLng(51.514232,-0.004952));
places.push(new google.maps.LatLng(51.5335909,-0.0309249));
places.push(new google.maps.LatLng(51.5579346,-0.0579472));
places.push(new google.maps.LatLng(51.4982361,-0.0088063));
places.push(new google.maps.LatLng(51.5130145,-0.0111308));
places.push(new google.maps.LatLng(51.563465,-0.079801));
places.push(new google.maps.LatLng(51.5121976,-0.0346867));
places.push(new google.maps.LatLng(51.5680057,-0.058456));
places.push(new google.maps.LatLng(51.5452938,-0.0733838));
places.push(new google.maps.LatLng(51.5641939,-0.083132));
places.push(new google.maps.LatLng(51.5173212,-0.0659308));
places.push(new google.maps.LatLng(51.5163506,-0.0458943));
places.push(new google.maps.LatLng(51.5883526,0.0289122));
places.push(new google.maps.LatLng(51.5883695,0.0268919));
places.push(new google.maps.LatLng(51.5800011,0.0277175));
places.push(new google.maps.LatLng(51.5623138,0.0338847));
places.push(new google.maps.LatLng(51.6142607,0.026283));
places.push(new google.maps.LatLng(51.616091,0.0249633));
places.push(new google.maps.LatLng(51.6080793,0.0379083));
places.push(new google.maps.LatLng(51.5781009,0.0231875));
places.push(new google.maps.LatLng(51.6196768,0.0266543));
places.push(new google.maps.LatLng(51.597442,0.0217368));
places.push(new google.maps.LatLng(51.5422898,0.2490011));
places.push(new google.maps.LatLng(51.5532075,0.2658116));
places.push(new google.maps.LatLng(51.5516327,0.2059849));
places.push(new google.maps.LatLng(51.5532453,0.2081838));
places.push(new google.maps.LatLng(51.523083,0.1909244));
places.push(new google.maps.LatLng(51.5347805,0.1915294));
places.push(new google.maps.LatLng(51.554561,0.241701));
places.push(new google.maps.LatLng(51.5670567,0.267669));
places.push(new google.maps.LatLng(51.543093,0.2014474));
places.push(new google.maps.LatLng(51.5163465,0.1972169));
places.push(new google.maps.LatLng(51.5551023,0.2481905));
places.push(new google.maps.LatLng(51.5562743,0.2602079));
places.push(new google.maps.LatLng(51.5252711,0.2099439));
places.push(new google.maps.LatLng(51.560035,0.251247));
places.push(new google.maps.LatLng(51.5632637,0.2153207));
places.push(new google.maps.LatLng(51.5540705,0.232055));
places.push(new google.maps.LatLng(51.567056,0.1020736));
places.push(new google.maps.LatLng(51.5818225,0.1005466));
places.push(new google.maps.LatLng(51.5702122,0.1354528));
places.push(new google.maps.LatLng(51.5632146,0.09764));
places.push(new google.maps.LatLng(51.58481,0.1353144));
places.push(new google.maps.LatLng(51.5709957,0.1398332));
places.push(new google.maps.LatLng(51.5642936,0.1126811));
places.push(new google.maps.LatLng(51.5755607,0.1256731));
places.push(new google.maps.LatLng(51.5695084,0.1112345));
places.push(new google.maps.LatLng(51.5632046,0.1162233));
places.push(new google.maps.LatLng(51.5597068,0.1211825));
places.push(new google.maps.LatLng(51.5970526,0.0632314));
places.push(new google.maps.LatLng(51.6147225,0.1133033));
places.push(new google.maps.LatLng(51.5750244,0.0532714));
places.push(new google.maps.LatLng(51.6069224,0.1054889));
places.push(new google.maps.LatLng(51.6028455,0.0941086));
places.push(new google.maps.LatLng(51.580873,0.072025));
places.push(new google.maps.LatLng(51.548435,0.071055));
places.push(new google.maps.LatLng(51.5808727,0.0720247));
places.push(new google.maps.LatLng(51.5791421,0.0813998));
places.push(new google.maps.LatLng(51.5679589,0.081192));
places.push(new google.maps.LatLng(51.5892674,0.0783834));
places.push(new google.maps.LatLng(51.5907301,0.0800816));
places.push(new google.maps.LatLng(51.5607437,0.0833874));
places.push(new google.maps.LatLng(51.5808754,0.0744209));
places.push(new google.maps.LatLng(51.538283,0.0105483));
places.push(new google.maps.LatLng(51.541641,0.0019137));
places.push(new google.maps.LatLng(51.5477407,0.0012295));
places.push(new google.maps.LatLng(51.5350135,0.0518739));
places.push(new google.maps.LatLng(51.5252477,0.0487678));
places.push(new google.maps.LatLng(51.5314398,0.0246504));
places.push(new google.maps.LatLng(51.5488693,0.0239897));
places.push(new google.maps.LatLng(51.5122514,0.0370009));
places.push(new google.maps.LatLng(51.5257248,0.036867));
places.push(new google.maps.LatLng(51.5513945,0.0551641));
places.push(new google.maps.LatLng(51.5226996,0.0136386));
places.push(new google.maps.LatLng(51.5397454,0.0393965));
places.push(new google.maps.LatLng(51.5159998,0.0453549));
places.push(new google.maps.LatLng(51.5715901,0.1608872));
places.push(new google.maps.LatLng(51.5661544,0.1737602));
places.push(new google.maps.LatLng(51.5761013,0.1940074));
places.push(new google.maps.LatLng(51.6042339,0.2244199));
places.push(new google.maps.LatLng(51.5734283,0.1709178));
places.push(new google.maps.LatLng(51.5779593,0.1787545));
places.push(new google.maps.LatLng(51.5976485,0.1551643));
places.push(new google.maps.LatLng(51.5962335,0.1791958));
places.push(new google.maps.LatLng(51.5879796,0.1596582));
places.push(new google.maps.LatLng(51.6012052,0.1598092));
places.push(new google.maps.LatLng(51.5870138,0.2005097));
places.push(new google.maps.LatLng(51.605718,0.220131));
places.push(new google.maps.LatLng(51.602133,0.173355));
places.push(new google.maps.LatLng(51.5970399,0.1589185));
places.push(new google.maps.LatLng(51.5810767,0.18231));
places.push(new google.maps.LatLng(51.5634023,0.1983883));
places.push(new google.maps.LatLng(51.5768061,0.209167));
places.push(new google.maps.LatLng(51.584641,0.2104854));
places.push(new google.maps.LatLng(51.5856093,0.2225428);
places.push(new google.maps.LatLng(51.5729451,0.2217085));
places.push(new google.maps.LatLng(51.593714,0.2337961));
places.push(new google.maps.LatLng(51.59470350.2361404));
places.push(new google.maps.LatLng(51.5637974,-0.0207901));
places.push(new google.maps.LatLng(51.5858122,-0.0017461));
places.push(new google.maps.LatLng(51.5941921,-0.0357694));
places.push(new google.maps.LatLng(51.5819628,-0.0064761));
places.push(new google.maps.LatLng(51.5636814,-0.0118063));
places.push(new google.maps.LatLng(51.5730457,-0.0088001));
places.push(new google.maps.LatLng(51.6095357,0.0029351));
places.push(new google.maps.LatLng(51.5744304,0.0075682));
places.push(new google.maps.LatLng(51.6020661,-0.0035885));
places.push(new google.maps.LatLng(51.562898,0.0119946));
places.push(new google.maps.LatLng(51.5875529,-0.0222263));
places.push(new google.maps.LatLng(51.5969479,-0.0135736));
places.push(new google.maps.LatLng(51.5798234,-0.036389));

var infowindow;

for (var i = 0; i < places.length; i++) {
    var marker = new google.maps.Marker({
        position: places[i],
        map: map,
        title: 'Place number ' + i
    });

    (function(i, marker) {
        google.maps.event.addListener(marker, 'click', function() {
            if (!infowindow){
                infowindow = new google.maps.InfoWindow();
            }
            infowindow.setContent('Place number ' + i);
            infowindow.open(map, marker);
        });
    })(i, marker);
}
}

google.maps.event.addDomListener(window, 'load', initialize);

</script>
</head>

<body>

<div id="map-canvas"/>
</body>
4

1 回答 1

2

基本上,您的位置数组中有错字/错字:

places.push(new google.maps.LatLng(51.59470350.2361404));

应该有一个逗号:

places.push(new google.maps.LatLng(51.5947035, 0.2361404));

作为旁注,您有一个 self-closing div,它是无效的 HTML,它应该是<div id="map-canvas"></div>

于 2013-11-12T18:27:19.480 回答