0

I just displayed a path between to locations in Google Map using this code.

   double srclat=8.8854;
   double srclong=76.5833;
   double destlat=9.0544;
   double destlong=76.5353;

  Intent i = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://maps.google.com /maps?saddr="+srclat+","+srclong+"&daddr="+destlat+","+destlong));
    startActivity(i);   

Now I wan to know that can I draw path in Google Map like A to B then B to C then C to D. using this method or something like this

Thanks in advance

Anandhu
  • 312
  • 2
  • 20
  • use google map api v2. use the polylines to draw path between points. check the link @ https://developers.google.com/maps/documentation/android/shapes – Raghunandan May 26 '13 at 03:33
  • @Raghunandan I refer the above link. now it shows that : 05-25 06:39:30.751: E/dalvikvm(1906): Could not find class 'com.google.android.gms.maps.model.PolylineOptions', referenced from method com.eple.router.MainActivity.onCreate , but I already imported the required packages. – Anandhu May 26 '13 at 04:05
  • Now the above code is not working.. please help.. – Anandhu May 26 '13 at 05:04
  • Now it's working but can't draw path between multiple locations.. – Anandhu May 26 '13 at 05:18
  • @Anandhu - do you want to show driving routes? – Rachel Gallen May 26 '13 at 05:24
  • @Anandhu this link may help http://stackoverflow.com/questions/13563098/show-routes-between-multiple-points-on-google-maps – Rachel Gallen May 26 '13 at 05:30
  • @RachelGallen Yes, driving routes. – Anandhu May 26 '13 at 06:06
  • @Anandhu you can draw paths between multiple location using polylines. but you need to modify the code accordingly – Raghunandan May 26 '13 at 13:46
  • @Raghunandan When I trying to use the Polylines and MapFragment. It shows an exception in logcat like The com.google.android.gms.maps.MapFragment can't be located . But I already included the google play services. – Anandhu May 26 '13 at 16:54
  • @Anandhu can u post the code and the logcar for further assistance. Also did you update adt to rev 22? – Raghunandan May 26 '13 at 16:57
  • @Anandhu how did you refer google play services library in your android project. If you follow the steps correctly in the link you should be able to get the map – Raghunandan May 26 '13 at 17:03

1 Answers1

0

I can draw Google Map Polyline using these steps :

  1. Implement Google Map v2 on Android (obviously)
  2. Get the JSON response from google directions API from this link http://maps.googleapis.com/maps/api/directions/json (try googling a few documentations or examples),

    Specify the starting lat-long and destination lat-long, for example : Follow this link, the result is a JSON response, and you can read it online using This JSON Formatter

  3. Parse the JSON response, it has a JSON Object called overview polyline, which contains the polyline data that you need to draw.
  4. Grab the points data inside overview_polyline
  5. Draw polyline using this method :

    Map.addPolyline(new polylineOptions().addAll(decodePolyLine(polyline)))

If implemented correctly, you should be able to draw a polyline successfully. Please do try to read some documentations, it does help :)

Good luck ^^

reidzeibel
  • 1,622
  • 1
  • 19
  • 24