Google changed its map API for Android and introduced API V2. The previous codes for drawing path are not working with API V2.
I have managed to draw a path with API V2. I had searched a lot for the solution but did not find any answer. So I am sharing its answer.
Dont know whether I should put this as answer or not...
I used @Zeeshan0026's solution to draw the path...and the problem was that if I draw path once, and then I do try to draw path once again, both two paths show and this continues...paths showing even when markers were deleted... while, ideally, old paths' shouldn't be there once new path is drawn / markers are deleted..
going through some other question over SO, I had the following solution
I add the following function in Zeeshan's class
in my map activity, before drawing the path, I called this function.. example usage as per my app is
you can use
rt.clearRoute();
as per your requirements.. Hoping that it will save a few minutes of someone else and will help some beginner in solving this issue..Complete Class Code
see on github
Edit: here is part of code from mainactivity..
Edit 2 as per comments
usage :
in below code midpointsList is an ArrayList of waypoints
Then copy and paste this url in your browser to check And the below code is to parse the url
And then pass the result to the drawPath method
decode poly function is to decode the points(lat and long) provided by Directions API in encoded form
First of all we will get source and destination points between which we have to draw route. Then we will pass these attribute to below function.
This function will make the url that we will send to get Direction API response. Then we will parse that response . The parser class is
This parser will return us string. We will call it like that.
Now we will send this string to our drawpath function. The drawpath function is
Above code will draw the path on mMap. The code of decodePoly is
As direction call may take time so we will do all this in Asynchronous task. My Asynchronous task was
I hope it will help.