Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open map to show direction from current location through intent-Android

I have many latitude longitude in my android app. I want to know how to open a chooser or Google map App through intent and show direction from current location to that latitude and longitude.Like i have lat=28.605989,lon=77.372970 and my current location is somewhere so when i click on button in my app these lat lon pass through intent and will show direction from my current location to these lat lon. Thank you.

like image 534
Gourav Manuja Avatar asked Dec 18 '22 21:12

Gourav Manuja


2 Answers

To navigate user to destination lat long, we can use something like this

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?daddr=28.605989,77.372970"));
startActivity(intent);

Here . we are passing just destination lat long daddr=28.605989,77.372970, so by default, your current location will be source location.

To add extra information with your url .

String my_data= String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=20.5666,45.345(My Destination Place)");

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(my_data));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
like image 59
Tejas Pandya Avatar answered May 12 '23 04:05

Tejas Pandya


You can send intent to Google Map android application by following code:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr=22.458,34.34&daddr=75.124,35.448"));
startActivity(intent);

In the above URI saddr represents the source address i.e. your current location and daddr represents the coordinates of the destination location.

like image 23
Ankit Mehta Avatar answered May 12 '23 06:05

Ankit Mehta