Open Inbuilt Map Intent For Driving Direction - android

I want to open an inbuilt google map intent to show route between two place without open a complete action dialog, which asked for Browser and Map .
I tried this.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+PreferenceData.getLatitude(HotelInfomation.this)+","+PreferenceData.getLongitude(HotelInfomation.this)+"&daddr="+latitude+","+longitude));
startActivity(intent);
But it opens a dialog asking Complete Action Using Browser or map . I don't want that Dialog .

without open a complete action dialog, which asked for Browser and Map
In this case you need to tell android which application you want to use to display map.
Here you go
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+PreferenceData.getLatitude(HotelInfomation.this)+","+PreferenceData.getLongitude(HotelInfomation.this)+"&daddr="+latitude+","+longitude));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);

Intent intent = new Intent(
android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="
+ Data.map_latitude + ","
+ Data.map_longitude + "+&daddr="
+ Data.infoLatitude + ","
+ Data.infoLogitute + ""));

Related

How to show distance between two points on map

I have latitude and longutude of two points. I want to show the route between them by opening google maps from my app on button click. How to do so?
Use below code for getting show route in google map...
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("
http://maps.google.com/maps?" +"saddr=" + sourcelatLng + "&daddr=" + destlatlng;
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
If you want to open maps app with a route from your source to destination, you just need to start an activity with following intent.
Uri routeUri = Uri.parse("http://maps.google.com/maps?saddr=your-lat-1,your-lng-1&daddr=your-lat-2,your-lng-2");
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, routeUri);
startActivity(intent);
Replace your-lat/lng-1/2 with your latitude and longitude.

Not able to open directions in google map in android

I have one screen in app which shows address. Now I want to open google when while click on that address. And it have to show directions from current location to that address.
//code in app
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?daddr=28.5600697,77.2695753"));
startActivity(intent);
but it is not opening location only processing.
Try this
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?q=28.5600697,77.2695753"));
startActivity(intent);
and please let me know if it works.
Try something like this. this will Suppress chooser dialog when calling Google map using intent
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+Latitude+","+Longitude+"&daddr="+latitude+","+longitude));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Try this code
float storeLatitude = Float.parseFloat(storeList.latitude + "");
float storeLongitude = Float.parseFloat(storeList.longitude + "");
String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=%f,%f (%s)", storeLatitude, storeLongitude, "Store Address");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
First you need to fetch user's current Latitude and Longitude than use following :
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + mUserLatitude + ", " + mUserLongitude +
"&daddr=" + lat + ", " + lon));
startActivity(intent);
Where lat , lon is destination Latitude and Longitude resepectively.

How to hide intent in android?

I have an application with the google map usage. In my case I'm opening the google map, outside from an activity. I did the following,
Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri
.parse("http://maps.google.com/maps?daddr=" + latitude + "," + longitude + "&mode=driving"));
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
notificationIntent.setPackage("com.google.android.apps.maps");
notificationIntent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
context.startActivity(notificationIntent);
But when I'm opening the map It shows over my application. I need to avoid the showing of map on my application. In other words my app should be the top application. Is there a way to do this?

Voice Guidance for Google Maps Route in Android

My application calls Google Maps via an Intent to show best route between two points using this code:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?dirflg=d&saddr=" + String.valueOf(currentPosition.getPosition().latitude) + "," + String.valueOf(currentPosition.getPosition().longitude) + "&daddr=" + String.valueOf(currentDest.getPosition().latitude) + "," + String.valueOf(currentDest.getPosition().longitude)));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
I was wondering, is it possible to activate voice guidance for the route via a parameter in the URL?
Use this code for voice guidance and navigation
Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("google.navigation:q="
+Destination));
startActivity(i);

Suppress chooser dialog when calling Google map using intent

I want to call google map intent without showing "Complete Action Dialog"?
Is it possible? Here is my code.
String uri = "http://maps.google.com/maps?saddr=" + Utils.getLatitude(ShowDetails.this)+","+Utils.getLongitude(ShowDetails.this)+"&daddr="+userLatitude+","+userLongitude;
startActivity(new Intent(android.content.Intent.ACTION_DEFAULT, Uri.parse(uri)));
I dont want to show below dialog when calling google map intent . Any Help is appreciated .
Below code helps me to solve my question.
String uri = "http://maps.google.com/maps?saddr=" + Utils.getLatitude(ShowDetails.this)+","+Utils.getLongitude(ShowDetails.this)+"&daddr="+userLatitude+","+userLongitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Use the Google Maps URI rather than "http://[...] "
It goes something like this:
String uri = "geo:" + latitude + "," + longitude
Check out http://developer.android.com/guide/appendix/g-app-intents.html for the info.
Try ACTION_VIEW instead of ACTION_DEFAULT:
String uri = "geo:"+ latitude + "," + longitude;
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
check this Android doc Intents List and browse to "Google Maps".

Categories

Resources