开发者

google maps Uncaught TypeError: Cannot read property 'start_location' of undefined in google maps

开发者 https://www.devze.com 2023-03-05 00:03 出处:网络
Hi I have this simple function in JS for google maps and I get uncaught typeerror directionResult is google directions response object which is passed by other function to this function.

Hi I have this simple function in JS for google maps and I get uncaught typeerror

directionResult is google directions response object which is passed by other function to this function.

                var myRoute = directionResult.routes[0].legs[0];
                var warnings = document.getElementById("warnings_panel");

                for (var i=0;i<3;i++)
                {
                        warnings.innerHTML += "<br/><br/>start lat = " + myRoute.steps[i].start_location.lat() + 
                                                                    "start lng = " + myRoute.steps[i].sta开发者_高级运维rt_location.lng() + "<br />";
                        warnings.innerHTML += "end lat = " + myRoute.steps[i].end_location.lat() + 
                                                                    "end lng = " + myRoute.steps[i].end_location.lng() + "<br /> + Path :";     

                                    for(var path=0;path<myRoute.steps[i].path.length;path++)
                                            warnings.innerHTML += myRoute.steps[i].path[path];                              



                }//


Hard to tell without more information but I would check that the myRoute.steps array contains at least three elements.


The error is the length of myRoute.steps [myRoute.steps.length]

var myRoute = directionResult.routes[0].legs[0];
var warnings = document.getElementById("warnings_panel");
for (var i=0;i<myRoute.steps.length;i++)
{
    warnings.innerHTML += "<br/><br/>start lat = " + myRoute.steps[i].start_location.lat() + "start lng = " + myRoute.steps[i].start_location.lng() + "<br />";
    warnings.innerHTML += "end lat = " + myRoute.steps[i].end_location.lat() + "end lng = " + myRoute.steps[i].end_location.lng() + "<br /> + Path :";
    for(var path=0;path<myRoute.steps[i].path.length;path++)
        warnings.innerHTML += myRoute.steps[i].path[path];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消