I'm a beginner in the field of android and currently working on a cab app . In this app I need to implement Map and directions API, I went through couple of tutorials and got several APIs but i dont know how to draw the returned data on the map so guys please help.. need some guidance. Thank you
For the moment i've extracted the latlng of source and destination and have created a seperate MapActivity for showing directions.
Google Directions API gives you a polyline (a list of LatLng points to draw a nice curvy line) of the returned route in an encoded format in "overview_polyline"
and "polyline"
fields in the JSON it returns.
By decoding this data you can create a Polyline
object which is then drawn on the GoogleMap
. Writing your own decoder isn't too difficult, but there's also android-maps-utils library that contains a method for this and many other fancy things you might want to use on Google Maps related things.
An example use of this library would be something like
GoogleMap map = ...;
String encodedPolyline = readFromJson();
Polyline line = map.addPolyline(new PolylineOptions()
.addAll(PolyUtil.decode(encodedPolyline))
.width(5)
.color(Color.RED));