2

I want to draw route between 2 points in Google map with a pin mark at ends points. in this, user can choose any driving route like by car, by cycle, by walk. I have to show routing information like "2 miles ahead , left from next street" and also estimated time.so regarding this , I found a lot of tutorial on the internet. the best I found is:

http://code.google.com/p/j2memaprouteprovider/source/browse/#svn/trunk/J2MEMapRouteAndroidEx

which is very complex and slow.

next I found this one:

http://www.anddev.org/google_driving_directions_-_mapview_overlayed-t826.html

this one is very similar to what I want, except some feature. but it is outdated.

I also found that I have to use KML for this. but i don't want to use it because of complexity so is it necessary to use KML? is there any better way to do this? can i have full source code as I got confused by seeing chunk of code. thanks a lot in advance,.

2 Answers 2

4

rock,

The simplest solution for this is to open "Google Map Application" that is already installed in android device. Just pass the source and target location's latitude and longitude as a parameter and call the google map application as follows:

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+latitude_source+","+longitude_source+"&daddr="+latitude_dest+","+longitude_dest));
        startActivity(i);

Using this approach, you can also choose any driving route like by car, by cycle, by walk etc and other functionalities that is provided by application.

0

Google Directions API contains everything you need. I found it easier to learn how the service works before looking at any complete source code.

Basically you will have to execute a UrlConnection and read the input stream. If you paste a basic request into a browser, you can see how your input stream would look like. Ex: http://maps.googleapis.com/maps/api/directions/xml?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&sensor=false The result contains everything you would need but you will have to parse the result for information like step by step directions. Also the node called "overview_polyline" is what you would use to draw a complete route on the MapView. You could use the formula here to decode that polyline into a list of coordinates.