How to get directions between two places?

One of the challenges was to get the directions between two places obtained as input from the user.

So we read the Google Directions API provided by the Google Map Web Services. We understood that we needed to get the steps. A step is basically one line of direction, in layman’s terms. So the html_instructions in each step is what we needed.




//:::::::::::::::: Get the directions from google maps using curl :::::::::::::::::::::


$ch= curl_init();

curl_setopt($ch, CURLOPT_URL, "$origin&destination=$destination&sensor=false");

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch,  CURLOPT_RETURNTRANSFER, true);


$json_data_var = json_decode($data, true);



Lets quickly understand what the above code does? It uses the curl library to send a request to the googleapis in the specified format stores the json response object in the variable named $json_data_var as a array.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s