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

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.

Related

google map Travel mode: request a ride

is it possible to change travel mode google maps to request a ride tab on android when click button from my app?
i used :
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?daddr="+ mLocation.latitude + ","+ mLocation.longitude +"&f=d&dirflg=r"));
startActivity(intent);
but parameter dirflg only limited to:
dirflg=h - Switches on "Avoid Highways" route finding mode.
dirflg=t - Switches on "Avoid Tolls" route finding mode.
dirflg=r - Switches on "Public Transit" - only works in some areas.
dirflg=w - Switches to walking directions - still in beta.
dirflg=d - Switches to driving directions
Seems (request a ride -> taXi) and:
dirflg=x - Switches on "request a ride tab" - only works in some areas.
and you can use intent with request like this:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=-7.328306+112.715478&daddr=Jl.+Frontage+Ahmad+Yani+Siwalankerto&dirflg=x"));
startActivity(intent);
to get result like that:
(replace -7.328306+112.71547 by mLocation.latitude + "+"+ mLocation.longitude for your LatLng in request)

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

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 !!!!

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.

Intent for Google Maps 7.0.0 with location

At first I know that there are several similar questions on StackOverflow. Curriently I use the geo scheme for addressing points which can be handled by other apps.
Like in the example of the Android documentation (by the way it seems to be outdated the RFC it out!) I tried to use something like this:
geo:50.95144,6.98725?q=50.95144,6.98725%20(Disneyland)
So I get a intent chooser where I can select an App which showed me in case of Google Maps Disneyland with a marker on it. Now it seems that an update was installed which removes that support. I just get the message that this place cannot been found.
I tried to understand the RFC 5870 which defines the 'geo' URI Scheme. I don't get it exactly. It is correct that it is not possible at all to define a lable?
How can I link now a position to Google Maps?
The WhatsApp intent is:
START u0 {act=android.intent.action.VIEW
cat=[android.intent.category.BROWSABLE]
dat=https://maps.google.com/maps?q=loc:lat,lng+(You)&rlz=1Y1TXLS_enDE543DE543
flg=0x3000000 cmp=com.android.browser/.BrowserActivity (has extras)}
from pid 2115
So if you use the following intent URI:
String geoUri = "http://maps.google.com/maps?q=loc:" + lat + "," + lng + " (" + mTitle + ")";
...it should behave like WhatsApp. Furthermore it seems that some other geo apps trigger on this intent too. But it doesn't work for all geo apps!
This is working on the latest Google Maps v7.1 tested on my Nexus 4.
public static void launchGoogleMaps(Context context, double latitude, double longitude, String label) {
String format = "geo:0,0?q=" + Double.toString(latitude) + "," + Double.toString(longitude) + "(" + label + ")";
Uri uri = Uri.parse(format);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
Like in the example of the Android documentation (by the way it seems to be outdated the RFC it out!) I tried to use something like this
The four sample constructions in the documentation are:
geo:latitude,longitude
geo:latitude,longitude?z=zoom
geo:0,0?q=my+street+address
geo:0,0?q=business+near+city
You will notice that none of those have a "label" in parentheses, separated by a space from the rest of the Uri.
Now it seems that an update was installed which removes that support
That "support", if it existed before, was undocumented, and you should not have been relying upon it. You will also note that there are many mapping applications for Android, any of which the user could choose for a geo: Intent -- did you test all of these to see if your undocumented capability worked on all of them?
It is correct that it is not possible at all to define a lable?
I do not see any evidence of your label-in-parentheses syntax in that RFC. Though, I agree, these IETF RFC tend to be difficult to read.
How can I link now a position to Google Maps?
Drop the label-in-parentheses:
geo:50.95144,6.98725?q=50.95144,6.98725
And, since you don't need the ? part anymore, you could use:
geo:50.95144,6.98725
If your real question is "how can I link now a position to Google Maps and have it show my own label", probably you can't.
You are welcome to embed a mapping engine into your app (e.g., Google's Maps V2 for Android), in which case you can mark up the map to the limits of that engine's API for it. I would expect any serious mapping engine to support adding markers with some sort of label.

Android application need to detect if the user came back from Google Maps Intent

I'm making an App and I use the Google Maps navigation
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + mLat + "," + mLng + "&daddr=" + mLatitude + " , " + mLongitude + ""));
And if the user come back from this intent I want to show the rating bar for the place the user has navigated to.
Is startActivityForResult something I can use on Intent not from my application?
Or is there another way to detect the user did came back to my App?
I don't know if you can get back something from an Intent you just throw up in the air for Android to handle but...
I'd recommend showing the map within one of your own activity; this way you'd exactly know what the user has done and which pin they've selected. You can then setResult in that Activity and get back the information.
I know it involves little bit more of development but you'd have total control of the map view and what the user do there. I'm sure you've seen this but take a look.
http://developer.android.com/resources/tutorials/views/hello-mapview.html
-serkan

Categories

Resources