Having seen a simple hard coded directions example yesterday, today we will have a look at another simple example but not an hard coded one. In today's example we will see the directions between different states in India. We have two simple list boxes stating Origin and Destination as lists of the states in India. You can select a state from either of the lists and then you will get the directions between the two selected cities.
If you see yesterday's code and today's code you will find a lot of similarities and so it would be easy to follow. The code will look lengthy, but it is just because of the list boxes code. So don't worry about the code, just go for it.
Note: The above code will not display any results if one of the two selected states is one of Arunachal Pradesh, Himachal Pradesh, Jammu & Kashmir, Mizomar, Uttar Pradesh, Andaman & Nicobar Islands or Lakshadeep Islands. The reason for this is not known to me. If anyone does know the reason please let us all know. Leave a comment!
If you see yesterday's code and today's code you will find a lot of similarities and so it would be easy to follow. The code will look lengthy, but it is just because of the list boxes code. So don't worry about the code, just go for it.
The output of the above code will look as seen in the results section above. Hope you find this code helpful in understanding the directions services even further. Tomorrow, we will look at another - a bit complex example. Till then, happy mapping.
Comments
Post a Comment
Please leave your comments here...