-1

I'm using the Petrousos 'Google Maps' book, and trying to run the example in the CHAPTER17/HTML/Directions Service.html downloaded from the book's website at www.mhprofessional.com at item 0071823026.

I had to adjust the table dimensions to get it to display properly, but otherwise made no changes. I'm running it through Firefox.

I set the origin and destination and clicked "Show Directions", at which point nothing happened.

The event called the following function:

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

I get as far as the directionsService.route call, but it is apparently not being executed, and status and result are not defined.

I have no idea how to debug this further, not having access to the API code..

Could the syntax of the call in the example be outdated?

I don't have an API key, but I understand it is not necessary, and I have run other examples without one.

user1067305
  • 3,233
  • 7
  • 24
  • 29
  • Please post a [Minimal, Complete, Tested and Readable example](http://stackoverflow.com/help/mcve) that demonstrates your issue (`Uncaught ReferenceError: printDirections is not defined`). The posted code works fine if I comment out the `printDirections` call and provide the missing data. – geocodezip Mar 31 '16 at 03:27

1 Answers1

-1

Do you old examples still work? If not, then it's because you don't have an API key. Google will shut you down after you surpassed the quota. I believe the quota is at 50 requests per hours.

Google has the most recent documentation (and it's impressively well documented)

https://developers.google.com/maps/documentation/directions/intro#Audience

Also, can you look at what the object returns? If so, that will usually indicate the quote being surpassed. You can do this by setting a breakpoint at the link

if (status == google.maps.DirectionsStatus.OK) {

If you're using Chrome, you can get to the debugger by right-clicking on the page adn choosing 'Inspect Element', then go to sources, find your line of code and click the link number to set a breakpoint.

TinyTheBrontosaurus
  • 4,010
  • 6
  • 21
  • 34