Monday, June 3, 2024
52
rated 0 times [  53] [ 1]  / answers: 1 / hits: 24862  / 12 Years ago, fri, april 20, 2012, 12:00:00
    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?


More From » google-maps-api-3

 Answers
15

You are missing (global var)



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


So directionsDisplay is undefined.


[#86117] Thursday, April 19, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
taliac

Total Points: 84
Total Questions: 114
Total Answers: 114

Location: Morocco
Member since Fri, May 22, 2020
4 Years ago
taliac questions
Sun, Mar 21, 21, 00:00, 3 Years ago
Tue, May 12, 20, 00:00, 4 Years ago
Mon, Jan 13, 20, 00:00, 4 Years ago
;