Launch Android Google Maps in directions mode, with "Avoid Highways" - android

In my Android app, I am trying to launch Google Maps in directions mode with "Avoid Highways" selected.
Using this code, I can launch Gmaps in turn-by-turn mode with "Avoid Highways":
public void openMapsApp(String destinationCoords)
{
Uri gmmIntentUri = Uri.parse("google.navigation:q="+destinationCoords+"&avoid=h");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
startActivity(mapIntent);
}
However, I want to launch Gmaps in directions mode, not turn-by-turn navigation mode. I want to do this because I want the user to be able to quickly change their destination without having to exit out of navigation mode first.
In my attempt at doing this, I change one line to:
Uri gmmIntentUri = Uri.parse("https://maps.google.com/?saddr=My+location&daddr="+destinationCoords+"&dirflg=h");
And this does launch Gmaps into directions mode. However, for some strange reason, dirflg=h stops working. This URL does set 'avoid highways' to true when I open it in a web browser, but for some reason it doesn't when I launch Gmaps.
What's extra strange is that in my app if I use a different value like dirflg=w or dirflg=r it launches Gmaps in walking and transit directions, respectively. It's only dirflg=h that doesn't work.
Anyone have any ideas?

Never mind, I resolved it by using dirflg=dh !!!!

Related

Android Auto NAVIGATE_INTENT Handling In Here Map shows no result.But works with google maps

Need to navigate from my android auto app car screen to Here maps app with geo coordinates. With google maps and waze I am able to start navigation. But Here map showing no results found.
Intent intent = new Intent(CarContext.ACTION_NAVIGATE)
.setData(Uri.parse("geo:13.11978,+80.14994"));
getCarContext().startCarApp(intent);
https://developer.android.com/training/cars/apps/navigation#support-navigation-intents
Is this because Navigation Intent is not handled. Any other methods to route navigation to here maps in android auto.
Try this:
Intent intent = new Intent(CarContext.ACTION_NAVIGATE)
.setData(Uri.parse("geo=0,0?q=N Park St,+Secretariat Colony,+Venkatapuram,+Ambattur,+Chennai,+Tamil Nadu 600053,+India"));
getCarContext().startCarApp(intent);
Check format No. 2 in this documentation:
https://developer.android.com/reference/androidx/car/app/CarContext#startCarApp(android.content.Intent)

Go from my application to the Google Maps application directly into the street view mode

I have developed a vehicle monitoring application that uses OSMDroid (Open Street Maps) to display the vehicle location and so on. Everything works fine.
However, I'm trying to make it such that when you press on a vehicle on the map, it automatically opens up Google Maps and, using the GPS coordinates of the vehicle, gets into street view immediately.
I cannot use Google Maps in my application because it's not free for business applications (at least, my boss told me that and I had to work with OSMDroid). I'm saying this simply because I don't want your answers to be "just use the google maps API" - I know I could, but I can't.
So the solution is - send the GPS information from my application as an intent to the Google Maps application that's already installed on the tablet.
Here's the code that I use:
#Override
public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
//on a tap on the bus map indicator, go to google maps in the particular location of the bus
Uri uri = Uri.parse("geo:"+gpsLatitude[0]+","+gpsLongitude[0]+"?z=" + map.getZoomLevel());
//set the data for the intent as the created uri
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
//go to the location of the bus
startActivity(intent);
return true;
}
Everything works well, and it goes to the Google Maps application and points to the location of the vehicle - the problem is, I haven't found any way to automatically get into street view at that particular location.
I found an answer here:
How to open a street view in virtual reality mode programmatically?
The code to do it is this one:
Intent streetView = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("google.streetview:cbll=27.173891,78.042068" + "&cbp=1,90,,0,1.0&mz=8"));
startActivity(streetView);
However, I'm not sure what the "&cpb" parameters represent.
Possible answer here: https://productforums.google.com/forum/#!topic/maps/aBj7qc8j0BI
Here's my new code - this time, I only get a black screen that's continuously loading:
#Override
public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
//on a tap on the bus map indicator, go to street view in the particular location of the bus
Uri googleMapsUri = Uri.parse("google.streetview:cbll="+gpsLatitude[0]+","+gpsLongitude[0]);
//set the data for the intent as the created uri
Intent mapIntent = new Intent(Intent.ACTION_VIEW,googleMapsUri);
// specify the google maps package
mapIntent.setPackage("com.google.android.apps.maps");
//go to the location of the bus
startActivity(mapIntent);
return true;
// Create a Uri from an intent string. Use the result to create an Intent.
Uri gmmIntentUri = Uri.parse("google.streetview:cbll=46.414382,10.013988");
// Create an Intent from gmmIntentUri. Set the action to ACTION_VIEW
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
// Make the Intent explicit by setting the Google Maps package
mapIntent.setPackage("com.google.android.apps.maps");
// Attempt to start an activity that can handle the Intent
startActivity(mapIntent);
https://developers.google.com/maps/documentation/urls/android-intents

Google Maps avoiding tolls, highways or ferries in turn by turn navigation intent

I am using Google Maps turn by turn navigation in my app to navigate from the current location to a given address. It works fine, my only problem is that I cannot set up avoid tolls/highways/ferries options via intent.
I followed google descriptions here: https://developers.google.com/maps/documentation/android-api/intents#launch_turn-by-turn_navigation
My code is the following with avoid tolls parameter:
String navigation = "google.navigation:q=" + latLng.latitude + "," + latLng.longitude + "&avoid=t";
Uri uri = Uri.parse(navigation);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);
Navigation starts fine, but it doesn't take notice of the avoid tolls parameter, it opens the driving route through roads, where tolls must be paid.
I also tried &dirflg=t and &avoid=tolls parameters, but no result.
Does anybody have some solution for this?
Thank you!
I think it's a bug in some of the android implementations on some devices.
I have the same problem. The same code runs fine on an A3 (2016), but not on an Xcover 3. Both on Lollipop (API 22) but on slightly different versions (newer on the A3). Maybe an update will help.

Start Android navigation for result

I am creating an app where I need to start the navigation app and then use the result (most importantly the driven distance). I am starting the navigation activity with startActivityForResult and using the scheme "google.navigation". Like this:
Intent i = new Intent(
Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=Somewhere"));
startActivityForResult(i,1);
This works great, I get a callback when the activity is done, but the data portion of the activity is empty.
Is there a way to do this?
Is there a navigation history where I can browse the latest trip for data?
Best Regards
Jakob Simon-Gaarde
Is there a way to do this?
No, there is no way for you to force an activity to give you a result. The determination of whether an activity supports a result lies in the authors of the activity, not the caller of the activity.
Is there a navigation history where I can browse the latest trip for data?
There is no documented and supported API for the Google Navigation Android app (which includes the google.navigation scheme).
I don't know about callbacks from Google Navigation. But if you are only interested in getting the driven distance, you could keep listening to the location updates in the background and calculate the distance yourself. The following function uses android.location.Location to calculate distance between two LatLang coordinates:
public double getGeodesicDistance(LatLng from, LatLng to){
Location _fromLoc = new Location("From location");
_fromLoc.setLatitude(from.latitude);
_fromLoc.setLongitude(from.longitude);
Location _toLoc = new Location("To location");
_toLoc.setLatitude(to.latitude);
_toLoc.setLongitude(to.longitude);
return Math.round(_fromLoc.distanceTo(_toLoc)); // distance in metres
}
But if you decide to take this approach, you should detect the sudden jumps in GPS data and handle them accordingly.
You could get the location right before you start the navigation, and get it again once the navigation is closed, and calculate the difference.

android app invoking google map with car,public,walking controls

Im having problems porting some functions of Iphone application to Android.
Basically iphone google map app that is invoked from this app looks like this
I have tried to copy similar behaviour using this pseudo code
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr="+LAT_POSITION+","+LONG_POSITION+"&daddr="+Lat+","+Lon + "&dirflg=w"));
startActivity(intent);
what it does it brings the android map app in this form
so then when i click show map i get
and then when i press back twice i get this
my questions are.
How I can get the (car,public,walk) controls overlay the map? just like in iphone app - on one screen (other elements too if possible)
additional question..
How I can enable showing map by default? (instead of textual directions, this is happening in android 2.2 - I have checked on samsung galaxy with froyo) , In 4.0 (emulator) the map is showing by default but still there are no overlay controls (car,public,walk).
You can use setComponent to explicitly tell the Maps app to use com.google.android.maps.MapsActivity to resolve the intent:
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + LAT_POSITION + "," + LONG_POSITION +
"&daddr=" + lat + "," + lon + "&dirflg=w"));
intent.setComponent(new ComponentName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity"));
startActivity(intent);
You should get the directions overlay but I'm not sure it will draw the route until the user hits "Go".
Of course this is "non API" and assumes that Maps is installed on the device and that Google will not change the internal packgage or class name for MapsActivity.

Categories

Resources