Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve “cannot call method … of undefined” error?

    function calcRoute() {
        var start = document.getElementById("start_").value;
        var end = document.getElementById("end_").value;
        var request = {
            origin: start,
            destination: end,
            travelMode: google.maps.TravelMode.DRIVING
        };
        directionsService.route(request, function (response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                directionsDisplay.setDirections(response);
            }
        });
    }

Gives an error message in Chrome: "Uncaught TypeError: Cannot call method 'setDirections' of undefined". Could anyone suggest fixing this? thanx

like image 986
kamal Avatar asked Apr 20 '12 11:04

kamal


1 Answers

You are missing (global var)

//var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer({ 'map': map }); 

So directionsDisplay is undefined.

like image 109
The Alpha Avatar answered Oct 13 '22 15:10

The Alpha