0
  function initialize() {

    var myOptions = {
    center: new google.maps.LatLng(45.652988, 25.611792),
    zoom: 12,
    mapTypeId: google.maps.MapTypeId.SATELLITE
    };

    var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

    var lines = new google.maps.Polyline({
                strokeColor: '#FF0000',
                strokeOpacity: 0.5,
                strokeWeight: 2,
                editable: true
                });

    nline = function setPolyline(points) {
    var path = lines.getPath();
    path.clear();
    path.push(points);
    lines.setMap(map);
    }

    google.maps.event.addListener(map, 'click', function() {
    var target = document.getElementById("info_panel");
    target.style.display = "none";
    });

    /*
    google.maps.event.addListener(line, 'click', function() {
    alert("you clicked polyline");
    });
    */
  }

在从 SQL 数据库执行 XMLHttpRequest 之后,另一个函数调用 setPolyline 函数(它位于地图初始化函数内部,因为“map”和“lines”变量只是局部变量而不是全局变量)作为参数传递一个 latlng 数组。

setPolyline 函数获取该数组,清除折线(名为“lines”)的路径,将 latlng 数组推入路径,并且在到达 setmap 指令时根本无法执行任何操作......

是否有嵌套问题或什么?...请帮助我在过去 6 小时内一直试图解决这个问题...

4

2 回答 2

0

你在哪里打电话lines.setPath(path)

于 2012-04-16T00:39:57.357 回答
0

尝试这个:

 function initialize() {

    var myOptions = {
    center: new google.maps.LatLng(45.652988, 25.611792),
    zoom: 12,
    mapTypeId: google.maps.MapTypeId.SATELLITE
    };

    var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

    var lines = new google.maps.Polyline({
                strokeColor: '#FF0000',
                path: linepth,
                strokeOpacity: 0.5,
                strokeWeight: 2,
                editable: true
                });

    nline = function setPolyline(points) {
    var linepth= [];
    var path = lines.getPath();
    path.clear();
//    path.push(points);
    linepth.push(points);
    lines.setMap(map);
    }

    google.maps.event.addListener(map, 'click', function() {
    var target = document.getElementById("info_panel");
    target.style.display = "none";
    });

    /*
    google.maps.event.addListener(line, 'click', function() {
    alert("you clicked polyline");
    });
    */
  }
于 2018-05-11T18:45:57.383 回答