"firstname": "John2"の無効なラベル エラーが発生します。json データを括弧に入れたのに、なぜこのエラーがまだ発生するのですか? コードが Java スクリプト ラベルと混同しているように、まだ何かが不足していますか?
<script type="text/javascript">
var data = "(" + {
"firstname": "John1",
"lastname": "Doe",
"location": {
"latitude": "48.4048403957642",
"longitude": "2.68452644348145"
}
}
{
"firstname": "John2",
"lastname": "Doe",
"location": {
"latitude": "48.4050236871384",
"longitude": "2.68512690051361"
}
}
{
"firstname": "John3",
"lastname": "Doe",
"location": {
"latitude": "48.4048403957642",
"longitude": "2.68452644348145"
}
}
+ ")" ;
function initialize() {
var center = new google.maps.LatLng(48.404840395764175, 2.6845264434814453);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var markers = [];
for (var i = 0; i < data.length; i++) {
var location = data[i];
var latLng = new google.maps.LatLng(location.latitude,
location.longitude);
var marker = new google.maps.Marker({
position: latLng
});
markers.push(marker);
}
var markerCluster = new MarkerClusterer(map, markers);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>