2

我正在从 xml 文件中读取 lat/long 的集合,并将其绘制为谷歌地图上的标记。除此之外,我根据“飞行坐标示例”将标记与折线连接起来。

我的问题是我需要在绘制折线之前发出警报(“anything”),否则标记不会显示在地图上。我怀疑这与加载地图有关,但不知道如何通过它?尝试过 setinterval,创建了一个繁忙的循环,但没有解决我的问题。任何援助将不胜感激。另外,如果代码没有显示在一个块中,请道歉

  function initialize() {

    var myOptions = {
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.SATELLITE
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var ctaLayer = new google.maps.KmlLayer('http://xxx.kmz');
    ctaLayer.setMap(map);

    var flightPlanCoordinates = new Array()

    downloadUrl("incident/breadCrumb.xml" + "?dummy=" + Math.random(), function (data) {
        var markers = data.documentElement.getElementsByTagName("marker");

        for (var i = 0; i < markers.length; i++) {

            var id = markers[i].getAttribute("id");
            var inspector = markers[i].getAttribute("inspector");
            var gpsDateTime = markers[i].getAttribute("gpsDateTime");
            var gpsLat = markers[i].getAttribute("gpsLat");
            var gpsLong = markers[i].getAttribute("gpsLong");
            var latlng = new google.maps.LatLng(gpsLat, gpsLong);
            var marker = createMarker(id, inspector, gpsDateTime, gpsLat, gpsLong, latlng);
             flightPlanCoordinates[i] = new google.maps.LatLng(gpsLat, gpsLong);

        }
    });


alert("Data Ready") 
/// This is where the problem is, when I uncomment this alert the polylines do not show, 
///when it is in place it works??? WTF?

var flightPath = new google.maps.Polyline({
        path: flightPlanCoordinates,
        strokeColor: "#FF0000",
        strokeOpacity: 1.0,
        strokeWeight: 2
    });

    flightPath.setMap(map);
   }


function createMarker(id, inspector, gpsDateTime, gpsLat, gpsLong, latlng) {
    var marker = new google.maps.Marker({ position: latlng, map: map });
    //      

    var contentString = '<div id="content" style="width:250px; height:250px; vertical-align: top; overflow: scroll;">' +
    '<table border="0" cellpadding="0" cellspacing="0" style="FONT-SIZE: 11px; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; width:300px;">' +

   '<td >ID</td><td >' + id + '</td></tr>' +
  '<tr><td >inspector</td><td >' + inspector + '</td></tr>' +
  '<tr><td >gpsDateTime</td><td >' + gpsDateTime + '</td></tr>' +
  '<tr><td >gpsLat</td><td >' + gpsLat + '</td></tr>' +
  '<tr><td >gpsLong</td><td >' + gpsLong + '</td></tr>' +
   '</div>';

    google.maps.event.addListener(marker, "click", function () {
        if (infowindow) infowindow.close();

        infowindow = new google.maps.InfoWindow({ content: contentString, maxWidth: 600 });
        infowindow.open(map, marker);
    });
    return marker;
}
4

0 回答 0