Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 推送通过单独AJAX查询获得的坐标后,无法在地图上添加多段线?_Javascript_Google Maps_Google Maps Api 3_Xmlhttprequest_Overlays - Fatal编程技术网

Javascript 推送通过单独AJAX查询获得的坐标后,无法在地图上添加多段线?

Javascript 推送通过单独AJAX查询获得的坐标后,无法在地图上添加多段线?,javascript,google-maps,google-maps-api-3,xmlhttprequest,overlays,Javascript,Google Maps,Google Maps Api 3,Xmlhttprequest,Overlays,从SQL数据库执行XMLHttpRequest后,另一个函数调用位于map初始化函数内的setPolyline函数,因为map和lines变量只是局部变量,而不是全局变量,作为latlng数组的参数传递 setPolyline函数获取该数组,清除多段线的命名线路径,将latlng数组推入该路径,当到达setmap指令时,根本无法执行任何操作 是否存在嵌套问题或其他问题?…请帮助我在过去6个小时内一直在尝试解决此问题…您是否在任何地方调用lines.setPathpath?尝试以下操作: fu

从SQL数据库执行XMLHttpRequest后,另一个函数调用位于map初始化函数内的setPolyline函数,因为map和lines变量只是局部变量,而不是全局变量,作为latlng数组的参数传递

setPolyline函数获取该数组,清除多段线的命名线路径,将latlng数组推入该路径,当到达setmap指令时,根本无法执行任何操作

是否存在嵌套问题或其他问题?…请帮助我在过去6个小时内一直在尝试解决此问题…

您是否在任何地方调用lines.setPathpath?

尝试以下操作:

  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");
    });
    */
  }
 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");
    });
    */
  }