Intent to Google Navigation for itinerary with several waypoints - android

I want to know, if it's possible to put several "checkpoints" within "Google Navigation" (Google Maps Navigation) With a query that follows the next syntax : "google.navigation:q=44.871709,-0.505704...."
If it possible, what is the syntax for separate two points ?
For one point it works, example : "google.navigation:q=44.871709,-0.505704"
But I would put a few checkpoints for example :
LatLng point1 = new LatLng(44.871709,-0.505704);
LatLng point2 = new LatLng(43.572665,3.871447);
Intent(android.content.Intent.ACTION_VIEW,Uri.parse("google.navigation:q="+
point1.latitude+","+point1.longitude+";"+ point2.latitude+","+point2.longitude));
I read others issues, they say to use this syntax :
"http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447"
With above solution, "Google Navigation" is not started automatically, we must choose one application "Google Maps" and next, to click on Itinerary (in top of the screen) to start "Google Navigation".
I would like to avoid it if possible.

Here is a way to supress the dialog and go to maps directly.
String uri = "http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447";
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);
Let me know if you still have issues.
UPDATE
As of May 2017, there is a better approach, the Google Maps URLs API
https://developers.google.com/maps/documentation/urls/guide
Using this API you can construct an URL with origin, destination and waypoints and pass it to the intent
String uri = "https://www.google.com/maps/dir/?api=1&origin=Madrid,Spain&destination=Barcelona,Spain&waypoints=Zaragoza,Spain%7CHuesca,Spain&travelmode=driving&dir_action=navigate";
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);

Check these 2 methods, both of them work properly for me.
METHOD 1:
String packageName = "com.google.android.apps.maps";
String query = "google.navigation:q=49.4839509,8.4903999";
Intent intent = this.getPackageManager().getLaunchIntentForPackage(packageName);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(query));
startActivity(intent);
METHOD 2:
String packageName = "com.google.android.apps.maps";
String query = "google.navigation:q=49.4839509,8.4903999";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(query));
intent.setPackage(packageName);
startActivity(intent);

Because point1.longitude is Double,you should use this
String.valueOf(point1.latitude);
Intent(android.content.Intent.ACTION_VIEW,Uri.parse("google.navigation:q="+String.valueOf(point1.latitude)+","+String.valueOf(point1.longitude)+";"+String.valueOf( point2.latitude)+","+String.valueOf(point2.longitude)));
Or you can use this,but it is just the same.
point1.toString().replace("lat/lng: (", "").replace(")", "")
point1.toString() the result is "lat/lng: (44.871709,-0.505704)",remove the "lat/lng: (" and ")".
then you can get the result that you want.
Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+point1.toString().replace("lat/lng: (", "").replace(")", "")+"&daddr="+point2.toString().replace("lat/lng: (", "").replace(")", "")));
Or you can try this
Uri uri = Uri.parse("http://maps.google.com/mapssaddr="+point1.toString().replace("lat/lng: (", "").replace(")", "")+"&daddr="+point2.toString().replace("lat/lng: (", "").replace(")", ""));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
I hope this can help you.

You have to just pass destination location. Google Maps app will automatically take your current location for navigation.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + String.valueOf(destination latitude)
+ "," + String.valueOf(destination longitude)));
startActivity(intent);

Related

How can I ask the user for Yandex Navi or Google Maps? How can I direct it?

I have two values in latitude and longitude. I have a key. This button must have two options to go to location information,Yandex Navi and Google Maps. When I click on the button, I want to know which one would like to open it. How can I do that?
You can use Intent.createChooser() like:
String url = "yandexmaps://maps.yandex.ru/?pt=" + latitude + "" + longitude + "&z=12&l=map";
Intent intentYandex = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intentYandex.setPackage("ru.yandex.yandexmaps");
String uriGoogle = "geo:" + latitude + "," + longitude;
Intent intentGoogle = new Intent(Intent.ACTION_VIEW, Uri.parse(uriGoogle));
intentGoogle.setPackage("com.google.android.apps.maps");
String title = "Select";
Intent chooserIntent = Intent.createChooser(intentGoogle, title);
Intent[] arr = new Intent[1];
arr[0] = intentYandex;
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr);
startActivity(chooserIntent);
Andrii Omelchenko's answer always opens Google Maps for me. But after change google and Yandex order for chooserIntent, it is worked in my case:
val uriYandex = "yandexnavi://build_route_on_map?lat_to=${latitude}&lon_to=${longitude}"
val intentYandex = Intent(Intent.ACTION_VIEW, Uri.parse(uriYandex))
intentYandex.setPackage("ru.yandex.yandexnavi")
val uriGoogle = Uri.parse("google.navigation:q=${latitude},${longitude}&mode=w")
val intentGoogle = Intent(Intent.ACTION_VIEW, uriGoogle)
intentGoogle.setPackage("com.google.android.apps.maps")
val chooserIntent = Intent.createChooser(intentYandex, title)
val arr = arrayOfNulls<Intent>(1)
arr[0] = intentGoogle
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr)
val activities = packageManager.queryIntentActivities(chooserIntent, 0)
if(activities.size>0){
startActivity(chooserIntent)
}else{
//do sth..
}
If it absolutely has to be either Google Maps or Yandex Navi, the easiest way would probably be to figure out which one the user wants to use (via a dialogue or similar), and then set that as the target of a Map Intent. For example, here's an intent from Google's Android documentation that targets Google Maps by app name:
// Creates an Intent that will load a map of San Francisco
Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4194");
Intent mapIntent = new Intent(Intent.ACTION_VIEW,
gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
This should also work with Navi by setting the package to "ru.yandex.yandexnavi".
Note, though, that a more standard way to do this would be with a Map Intent that doesn't specify the targeted app. That way, all you would have to provide is the coordinates, and then the user could use their app of choice:
public void showMap(Uri geoLocation) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}

Unable to find the place in google map using Android in specific radius

I want to find places of interest under a specific radius using Android. I am working in this way
String uri = "geo:"+ 40.007620 + "," + -75.160264 +"&q=child hospitals";
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
But when I run the application, It opens the google maps but does not mark the child hospitals. Any wrong here?
Try this,
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("geo:<40.007620>,<-75.160264>?q=<40.007620>,<-75.160264>(child hospitals)"));
startActivity(intent);
Please check below reference which will guide you to how to pass or format map intent query data :
https://developers.google.com/maps/documentation/android-api/intents
Example :
Uri gmmIntentUri = Uri.parse("geo:40.007620,-75.160264?q=" + Uri.encode("child hospitals"));
Humty you can try to this code hope this can help you..
Uri gmmIntentUri = Uri.parse("geo:40.007620,-75.160264?z=10&q=child hospitals");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
You can try something like this :
String urlAddress =
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=lat,lng&radius=500&type=city hospital&keyword=hospital&key=YOUR_API_KEY
which you can pass to
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress);
startActivity(intent);
This will get opened in Google Maps with the results w.r.t provided radius. It works also same mentioned in below doc reference.
https://developers.google.com/places/web-service/search
Url to test :
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=18.590478,73.727191&radius=50000&type=child%20hospital&keyword=child%20hospital&key=PASTE_YOUR_API_KEY

Start Google Map Intent

hi i wanted to make a button which is the button will start google map intent
with my current location and destination location
how to make a google map automaticlly detect my location and destination longitude and lat?
where i put that longi and lat?
i want that map directly draw the direction to destination
final Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?"
+ "saddr="+ current_lat+","+current_longi + "&daddr="+dest_address ));
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(intent);
alr tried this code but not working
Try using one of these with the View intent:
geo:latitude,longitude
geo:latitude,longitude?z=zoom
geo:0,0?q=my+street+address
geo:0,0?q=business+near+city
Something like:
Uri uri = Uri.parse(<ONE OF THE ABOVE STRINGS>);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);
Try this one:
String url = "http://maps.google.com/maps?saddr="+currentLattitude+","+currentLongitude+"&daddr="+targetLat+","+targetLang+"&mode=driving";
it should work.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=srcLatitude,srcLongitude&daddr=destLatitude,destLongitude"));
startActivity(intent);
// srcLongitude/Latitude = current Location`s longitude/latitude
// destLongitude/Latitude = Destination Location`s longitude/latitude

How to draw a route between two markers points on Google Maps v2?

https://developers.google.com/maps/documentation/android/lines doc says by making the ".geodesic(true)" option, it will follow the curvature of the earth. But it just shows a straight line. Any suggestions?
try this code
String uri = "http://maps.google.com/maps?saddr=" +
currentLatitude+","+currentLongitude+"&daddr="+fixedLatitude+","+fixedLongitude;
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);
this might be help you

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