13

Possible Duplicate:
How to display a route between two geocoords in google maps?

I am looking for a way to get the route between 2 points displayed in the Map using Google Maps API v2. I have searched in SO but I can't find an example for this. Maybe someone can help me with links or an example.

Thanks a lot.

Community
  • 1
  • 1
Xelz
  • 1,059
  • 2
  • 11
  • 16
  • Is that what you are looking for? http://stackoverflow.com/questions/2643993/how-to-display-a-route-between-two-geocoords-in-google-maps – Waza_Be Dec 18 '12 at 20:12
  • Just a commento: Google maps API V2 will become deprecated on May 2013. Google is sending mails to developers in order to migrate their mashups to a newer version. – jap1968 Dec 18 '12 at 20:38
  • @jap1968 You are talking about the JavaScript API, but my question is about the Android Google Maps API v2. – Xelz Dec 18 '12 at 20:41
  • The answer from Waza_Be is the only way that will work. The API itself does not display routes. – Joe Malin Dec 18 '12 at 21:25

2 Answers2

20

In the v2 of the Maps API, a route is just a PolyLine. IMHO is way more convenient/easy to use than the old fashioned overlay.

From the Google Maps API V2 documentation:

Polyline line = map.addPolyline(new PolylineOptions()
                   .add(new LatLng(-37.81319, 144.96298), 
                        new LatLng(-31.95285, 115.85734))
                   .geodesic(true));
Robert Estivill
  • 12,369
  • 8
  • 43
  • 64
  • 1
    I'm using the same code you used, but some times the lines don't follow the streets or avenues, do you have a solution? – Raúl Omaña Jan 23 '13 at 12:42
  • 1
    The polyline doesn't have anything to do with streets or avenues. If they don't match, is because you are creating the polyline with the wrong coordinates. – Robert Estivill Jan 23 '13 at 16:28
0

The distance calculation is a method of the GLatLng object.

You can use something like this:

DISTANCE = markerOne.getPoint().distanceFrom(markerTwo.getPoint());

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/LatLng

Gabriel
  • 476
  • 2
  • 11
  • 64
  • Yeah, with that you can calculate the distance, but I'm looking for the route (group of points) between 2 coordinates. – Xelz Dec 18 '12 at 20:47