Getting driving directions

With the vast availability of map services from Google, Bing, Yahoo!, and even MapQuest, getting directions is very easy. We will explore how to use the Google Directions API to generate driving directions from one place to another.

Note

First, we need the request URL of the Google Directions API. Based on the documentation, the request URL is as follows:

http://maps.googleapis.com/maps/api/directions/output?parameters

The output can be either JSON or XML, depending on which format of output we want our result to be. We will be using JSON for our example. There are also required parameters such as those described in the following table:

Parameter

Description

origin

Beginning address

destination

Destination address ...

Get Getting Started with PhantomJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.