在这里,我正在创建一个功能,从 JSON 文件中检索纬度和经度。并在谷歌地图上显示标记。
但我的问题是谷歌地图上只显示了一个标记。其他不显示。
这是我的 json 格式
{
"Data": {
"-template": "Parallax",
"Explore": {
"IslandLife": {
"TourismLocation": [
{
"Title": "Langkawi",
"Latitude": "6.350000",
"Longitude": "99.800000",
"YouTubePlaylistID": "UUnTJRksbHP4O8JSz00_XRQA",
"VideosList": {
"YouTubeVideoID": [
"7HlMpaSspNs",
"tzeRnbd77HU",
"VkIAbDIVJCA",
"ksJ6kwTe9wM"
]
}
},
{
"Title": "Rawa Island",
"Latitude": "2.520278",
"Longitude": "103.975833",
"YouTubePlaylistID": "UUnTJRksbHP4O8JSz00_XRQA",
"VideosList": { "YouTubeVideoID": "Kx0dUWaALKo" }
},
{
"Title": "Perhentian Island",
"Latitude": "5.903788",
"Longitude": "102.753737",
"YouTubePlaylistID": "UUnTJRksbHP4O8JSz00_XRQA",
"VideosList": {
"YouTubeVideoID": [
"ZpcdGk5Ee0w",
"TQTDOGpflZY"
]
}
},
{
"Title": "Sabah Marine Park",
"Latitude": "4.623326",
"Longitude": "118.719800",
"YouTubePlaylistID": "UUnTJRksbHP4O8JSz00_XRQA",
"VideosList": { "YouTubeVideoID": "VCDTEKOqpKg" }
}
]
}
}
}
}
这是我的函数,我从上面的 json 文件中检索纬度和 lognitutde
<script type="text/javascript">
$.getJSON('json/explore.json', function(data) {
$.each(data, function(key, val) {
for (var i = 0; i < val.Explore.IslandLife.TourismLocation.length; i++) {
PlotMarker(val.Explore.IslandLife.TourismLocation[i].Latitude, val.Explore.IslandLife.TourismLocation[i].Longitude);
}
});
});
function PlotMarker(lat, lang) {
var mapProp = {
center: new google.maps.LatLng(lat, lang),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("gmap"), mapProp);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lang),
});
marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', PlotMarker);
</script>
<body>
<div id="gmap" style="width: 800px; height:500px;"></div>
</body>
如何在地图上显示多个标记???