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 GoogleMapAPI抛出JS错误_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript GoogleMapAPI抛出JS错误

Javascript GoogleMapAPI抛出JS错误,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,尝试设置一条线的动画,我已经理解了大部分代码。我得到一个错误,不知道为什么 以下是登录到控制台的错误。你可以看到哪里出了问题 控制台日志: c is (30.37470457, -97.76039932000003) get at depature is (30.37470457, -97.76039932000003) get at arrival is (30.39386213, -97.75522519000003) path is path.get

尝试设置一条线的动画,我已经理解了大部分代码。我得到一个错误,不知道为什么

以下是登录到控制台的错误。你可以看到哪里出了问题

控制台日志:

     c is (30.37470457, -97.76039932000003)
     get at depature is (30.37470457, -97.76039932000003)
     get at arrival is (30.39386213, -97.75522519000003)
     path is path.getPath() [object Object]
     steps is running
     are we there yet is(30.374781200646034, -97.76037862752048)
     steps is running
    js?key=secret&sensor=false&libraries=geometry:38 Uncaught TypeError: Cannot read property 'lat' of undefined_.Ob @ js?key=secret&sensor=false&libraries=geometry:38Gy.interpolate @ js?key=secret&sensor=false&libraries=geometry:125(anonymous function) @ 
     steps is running
    js?key=secret&sensor=false&libraries=geometry:38 Uncaught TypeError: Cannot read property 'lat' of undefined_.Ob @ js?key=secret&sensor=false&libraries=geometry:38Gy.interpolate @ js?key=secret&sensor=false&libraries=geometry:125(anonymous function) @ 
     steps is running
    js?key=secret&sensor=false&libraries=geometry:38 Uncaught TypeError: Cannot read property 'lat' of undefined_.Ob @ js?key=secret&sensor=false&libraries=geometry:38Gy.interpolate @ js?key=secret&sensor=false&libraries=geometry:125(anonymous function) @ 
     steps is running
JS代码:

    function drawPath2(run_id){
  var request = $.ajax({
    url: "/requester/potrip?r_id=" + r_id,
    type: "GET",
    dataType: "json"
  });

  request.done(function(data) {
    console.log("starting request done");
    var p = data['points'];
    var c = [];
    var bounds = new goog.LatLngBounds();
    for(var i = 0; i < p.length; i++){
      var l = new goog.LatLng(parseFloat(p[i][1]), parseFloat(p[i][0]));
      bounds.extend(l);

      c.push(l);
    }

    console.log("c is " + c);
    console.log("c is " + c[0]);
    departure = parseFloat(c[0][1]);
      arrival = parseFloat(c[c.length-1][0]);
    var path = createPoly(c, "head");
    map.fitBounds(bounds);
    path.setMap(null);

console.log("get at depature is " + path.getPath().getAt(0));
console.log("get at arrival is " + path.getPath().getAt(path.getPath().getLength()-1));
console.log("path is path.getPath() " + path.getPath());
    var step = 0;
 var numSteps = 250; //Change this to set animation resolution
 var timePerStep = 5; //Change this to alter animation speed
 var theLenght = path.getPath().getLength()-1;
 var interval = setInterval(function() {
     step += 1;
     console.log("steps is running");
     if (step > numSteps) {
      console.log("clearinginterval" + step);
         clearInterval(interval);
     } else {

         var are_we_there_yet = google.maps.geometry.spherical.interpolate(path.getPath().getAt(0),path.getPath().getAt(1),step/numSteps);
         console.log("are we there yet is" + are_we_there_yet);
         path.setPath([path.getPath().getAt(0), are_we_there_yet]); <-- ERROR
     }
 }, timePerStep);



  });

  request.fail(function(jqXHR, textStatus) {
    console.log( "Request failed: " + textStatus );
  });
}

你有一个逻辑问题。不能使用多段线的路径包含路径的最终值和插值。运行动画后,如果动画卡在长度为零的多段线上,则动画将停止运行

此代码适用于我:

var are_we_there_yet = google.maps.geometry.spherical.interpolate(
                         c[0], 
                         c[1], 
                         step / numSteps);
path.setPath([c[0], are_we_there_yet]);
代码片段:

var映射;
函数初始化(){
map=新建google.maps.map(
document.getElementById(“地图画布”){
中心:新google.maps.LatLng(37.4419,-122.1419),
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
animatePolyline(数据);
}
google.maps.event.addDomListener(窗口“加载”,初始化);
函数animatePolyline(数据){
//输入数据
var p=数据点;
//google.maps.LatLng对象数组
var c=[];
var bounds=new google.maps.LatLngBounds();
对于(变量i=0;inumSteps){
间隔时间;
}否则{
var are\u we\u there\u还=google.maps.geometry.spheremic.interpolate(c[0],c[1],步长/numSteps);
setPath([c[0],我们到了吗?);
}
},timePerStep);
}
风险值数据={
要点:[
[-72, 42],
[-73, 43]
]
};
html,
身体,
#地图画布{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}


请提供一个示例来说明错误。从错误中,我会说path.getPath().getAt(0)(或者我们还在那里)是未定义的。看起来你传递到
google.maps.geometry.sphereal.interpolate
中的任何东西都是错误的。你能链接到JSFIDLE吗?当我在小提琴中尝试上面的代码时,它会闪烁屏幕白色,什么都不会发生。小提琴在哪里(你在哪里试过代码)?Chrome中的代码片段对我很有效。我复制了你的代码,但该小提琴配置不正确。你能提供你的代码链接吗?你是在我的回答中要求提供代码片段的链接吗?
var are_we_there_yet = google.maps.geometry.spherical.interpolate(
                         c[0], 
                         c[1], 
                         step / numSteps);
path.setPath([c[0], are_we_there_yet]);