0

I know that you can draw paths using polylines this way:

PolylineOptions rectOptions = new PolylineOptions();
rectOptions.color(Color.RED);
String[][] lineInformation = ((MyApplication)getApplication()).getLineInformation(line);
for (int i=0; i<lineInformation.length; i++){
    rectOptions.add(new LatLng(Double.parseDouble(lineInformation[i][0]),Double.parseDouble(lineInformation[i][1])));
}

mMap.addPolyline(rectOptions);

But using that code, the lines will pass through edifices with straight lines and that's not the behaviour I'm searching for. I'm trying to draw the path through roadways which can be driven by a car.

Is that possible in Google Maps v2?

PS: the questions proposed by xomena in the comments are not applicable because they only work with two points, origin and destination.

halfer
  • 19,824
  • 17
  • 99
  • 186
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
  • Possible duplicate of [Android Google Maps: draw a route between two points, along the road](https://stackoverflow.com/questions/47492459/android-google-maps-draw-a-route-between-two-points-along-the-road) – xomena Mar 04 '18 at 21:30
  • Similar question https://stackoverflow.com/questions/47784512/plotting-coordinates-on-route-in-gmap-google-maps-android-api – xomena Mar 04 '18 at 21:32
  • @xomena that questions are for only two points, with directions api, which only works with two points, origin and destiniy. Do you know how to use a set of points with directions api? if yes please tell me, if not please delete your close and duplicate votes for this question please. – NullPointerException Mar 05 '18 at 17:28
  • The first answer draws a route between origin and destination using Directions API, the second do the same. Isn't it enough for you to follow these answers? – xomena Mar 05 '18 at 17:31
  • @xomena please read me, i don't have two points, origin and destination... i do have a lot of points where my route must pass, so directions api doesn't work for me – NullPointerException Mar 05 '18 at 17:32
  • Directions API has also waypoints parameter. Just add your intermediate points as waypoints in Directions API request and you are done: https://developers.google.com/maps/documentation/directions/intro#Waypoints – xomena Mar 05 '18 at 17:34
  • @xomena thank you I'm checking it. But it tells "Waypoints are not available for transit directions" What means transit? I'm not english native and for me transit is an abstract and general word. What do google mean with transit? – NullPointerException Mar 05 '18 at 17:37
  • See https://developers.google.com/maps/documentation/directions/intro#TravelModes. Basically it means public transit - buses, trains.... –  Mar 05 '18 at 17:39
  • Transit means public transport. The routes for public transport (bus, metro, train, etc) is predefined by transit agencies. – xomena Mar 05 '18 at 17:41
  • thank you so much @xomena it's seem it's working but one question more, why not for public transport? I'm generating this application specifically for map the route of a public transport bus of my city – NullPointerException Mar 05 '18 at 18:07
  • outh, what a problem, only 23 waypoints max per request... thats not enought for me :( – NullPointerException Mar 05 '18 at 18:09
  • Transit directions in API are provided by transit agencies in form of [GTFS feeds](https://developers.google.com/transit/gtfs/). The route is defined in GTFS itself and you cannot change it applying waypoints. If you construct the route yourself, just use driving mode. – xomena Mar 05 '18 at 18:12
  • You can split directions requests in chunks of 25 points: origin, destination and 23 waypoints and join resulting polylines. – xomena Mar 05 '18 at 18:13
  • @xomena with this GTFS file it's possible to get the positions of the route of each bus line and paint the map? did you have any reference or link about how to achieve it? there are only txt files full of data but hard to understand how to relate that data with each line and how to paint it. https://transitfeeds.com/p/emt-valencia/719/latest/download – NullPointerException Mar 05 '18 at 18:29
  • I think there is no easy way to get route polyline from GTFS directly, but directions api with transit mode should return routes according to GTFS. – xomena Mar 05 '18 at 18:31
  • @xomena finally I will use GTFS, thank you so much for your help. I didn't know about the existence of GTFS until you told me! Thank you so much. Are you working for google in the google maps project or something similar? your knonweledge about this is very huge. – NullPointerException Mar 06 '18 at 06:18

0 Answers0