4


I need to show the driving direction using external google map application i found this link http://developer.android.com/guide/appendix/g-app-intents.html ,but the below opens the Maps application to the given location

    Uri uri = Uri.parse("geo:13.070984,80.253639");
    Intent in = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(in);

I need to know is there is any way to pass two geo location to get driving direction.

ganesh
  • 1,247
  • 6
  • 24
  • 46

3 Answers3

13

yes its very easy to show the direction if you have the latitude and longitude of both source and destination. Just see the following code:

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

    startActivity(intent);

Where latitude_source=Latitude of your source longitude_source=Longitude of your source latitude_dest=Latitude of your destination longitude_dest=Longitude of your destination

Just replace these value with your actual data. .Use the above code on some particular event.

Hope this will help you.

Girish Nair
  • 5,148
  • 5
  • 40
  • 61
Dinesh Sharma
  • 11,533
  • 7
  • 42
  • 60
  • Note that this `Uri` pattern is not part of the Android SDK and therefore may stop working at any time. – CommonsWare Apr 02 '11 at 11:43
  • this works fine ,but is there any way to choose between Browser and Maps using Intent chooser. – ganesh Apr 02 '11 at 15:43
  • 2
    @ganesh, you mean you don't want the intent chooser to popup and want to just load in the Maps app? Then add this line of code `intent.setComponent(new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"));` – georgiecasey Nov 14 '12 at 02:37
  • @dinesh Sharma how do I get longtitude and lattitude ? I know only address in text format.. – Ashokchakravarthi Nagarajan Mar 28 '14 at 06:10
  • 1
    @CHAKRAVARTHI : please refer this link: http://stackoverflow.com/questions/3574644/how-can-i-find-the-latitude-and-longitude-from-address – Dinesh Sharma Mar 28 '14 at 14:13
0

You can get routing between two locations with the following URL.

https://maps.google.com/maps?saddr=kedah&daddr=johor

saddr is the start, and daddr is the destination.

Example code:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(String.format("http://maps.google.com/maps?saddr=kedah&daddr=johor")));
startActivity(intent);
Khantahr
  • 8,156
  • 4
  • 37
  • 60
0

I've implemented this by firing an intent that uses a Google Maps URL - the Maps application picks it up, and it works. I think it is not officially recommended, but for me is working well.

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(String.format(http://maps.google.com/maps?saddr=%s&daddr=%s, startAddress, endAddress)));
startActivity(intent);

The above works for location NAMES, you may need to tweak it to use lat/long. Here's an example Google Maps directions URL between two lat/long points that will be useful: http://maps.google.co.uk/maps?f=d&source=s_d&saddr=A685&daddr=M40&hl=en&geocode=FazjPwMdRKPc_w%3BFeS8GgMdNMfr_w&mra=me&mrsp=1,0&sz=5&sll=53.800651,-4.064941&sspn=22.244994,67.631836&ie=UTF8&t=h&z=5

Ollie C
  • 28,313
  • 34
  • 134
  • 217