我在php数组$ col_1_values_array中有一组lat长点用于纬度,$ col_2_values_array用于经度。我想在Google地图上映射所有这些点并在其上绘制路线。我已经用Javascript编写了这段代码,但它没有在点上显示标记。请帮我找出错误。
<script type="text/javascript">
$(document).ready(function() { initialize(); });
function initialize() {
var map_options = {
center: new google.maps.LatLng(<?php echo $col_1_values_array[0] ?>,<?php echo $col_2_values_array[0] ?>),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var google_map = new google.maps.Map(document.getElementById("map_canvas"), map_options);
var info_window = new google.maps.InfoWindow({
content: 'loading'
});
var x = [];
var y = [];
var routePoints = [];
for(<?php $r=0;$r<25;$r++ ?>)
{
x.push(<?php echo $col_1_values_array[$r]?>);
y.push(<?php echo $col_2_values_array[$r] ?>);
}
var i = 0;
for (var p=0;p<25;p++) {
routePoints.push(new google.maps.LatLng(x[p],y[p]));
var m = new google.maps.Marker({
map: google_map,
animation: google.maps.Animation.DROP,
title: t[p],
position: new google.maps.LatLng(x[p],y[p]),
html: h[i]
});
var route= new google.maps.Polyline({
path: routePoints,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
google.maps.event.addListener(m, 'click', function() {
info_window.setContent(this.html);
info_window.open(google_map, this);
});
i++;
}
route.setMap(google_map);
}
</script>
答案 0 :(得分:0)
您可能遇到计时问题,请尝试在初始化地图事件中执行标记工作。 google.maps.event.addDomListener(窗口,&#39;加载&#39;,初始化);