Android Navigation intent
Asked Answered
S

3

1

If you mail a Google Maps direction to your Android phone, you have the possibility to open it in the Maps appliaction, this seems perfectly logical, as does the code behind it.

Now, once in the Maps App, you have the possibility to open these directions in the Navigation App, with those exact directions.

How does this work? It must not be that difficult to do it, I know about the intent with

"google.navigation:q=..."

But this only works on some devices and only with coördinates or addresses... No Maps directions?

Can anyone help me out with this?

EDIT:

This is what the URL looks like:

https://maps.google.com/maps?saddr=Durbanville,+Cape+Town,+Western+Cape,+South+Africa&daddr=Parow+North,+Cape+Town,+South+Africa+to:Somerset+West,+Cape+Town,+South+Africa+to:Milnerton,+Cape+Town,+South+Africa&hl=en&ll=-33.955037,18.657532&spn=0.25032,0.528374&sll=-33.911454,18.601913&sspn=0.250448,0.528374&geocode=FczB-_0dzIkcASlBKWkzGlfMHTFTuxOUSmpCAw%3BFQTi-v0d5oMbASld0qgMSFrMHTG2XqWY145Ttw%3BFfUG-P0dPHEfASk398T7ZbXNHTG5a6EH84n4Qg%3BFVU8-_0doEkaASnrz9UPVVnMHTFz2N4nnkA7XQ&oq=parow&mra=ls&t=m&z=12

Signatory answered 9/5, 2013 at 10:17 Comment(0)
N
10

If you create a web url in the format

http://maps.google.com/maps?saddr=[lat 1],[lon 1]&daddr=[lat 2],[lon 2]

where [lat 1] and [lon 1] are the latitude and longitude for the start point, and likewise [lat 2] and [lon 2] are the end point, and set it as a String, you can then send this to an intent:

Intent navIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(navigationUrl));
activity.startActivity(navIntent);

This will give the user the option of opening a Web Browser, Google Maps, or Navigation.

EDIT:

For multiple destinations add the following to the end of the url (for each additional place)

+to:[lat 3],[lon 3]

as required.

So for 4 destinations you would have:

http://maps.google.com/maps?saddr=[lat 1],[lon 1]&daddr=[lat 2],
  [lon 2]+to:[lat 3],[lon 3]+to:[lat 4],[lon 4]
Neoimpressionism answered 9/5, 2013 at 10:37 Comment(5)
I realise this is possible, but I have a maps url with a route that has at least 4 destinations in itSignatory
Well you didn't specify that in your original question... Answer updatedNeoimpressionism
This doesn't seem to work very well with large lists of locations. Actually, I am experiencing weirdness with anything more than a single "+to:" in my url. So even only going up to lat4,lon4 like in your example yields some unexpected results. Does this url format no longer work?Volkan
Any specific kind of weirdness? New Google Maps doesn't currently support multiple destinations if you are using that. Revert to old mapsNeoimpressionism
There doesn't seem to be rhyme or reason to it, but adding any more than one '+to:' creates a map with multiple paths back and forth from each point to some early point that is usually not the saddr. Additionally, all '+to:' points are not displayed and sometimes there will be markers for points that I didn't even pass in the url. I have an app where I am sending the url to the maps app via intent to open a map with a route displayed, reverting to old maps seems impossible in this situation, or am I mistaken?Volkan
C
0

After following answers above, I find myself in a country that Google Navigation service is not available. But the navigation intent still can be accomplished with Google Map by this:

Uri routeUri = Uri.parse("http://maps.google.com/maps?&saddr=" +
                                MyApplication.Lat + "," +
                                MyApplication.Lon + "&daddr=" + merchantAddr.getText());

Intent i = new Intent(Intent.ACTION_VIEW, routeUri);
startActivity(i);

It seems we can set the start point to Geo location with lat/lon, and end point to an address, and vice versa. The geo location seemed to be transformed to an address or road name in the Google Map.

Commensurable answered 8/7, 2013 at 2:0 Comment(0)
R
0

The url should like this:

String navigationUrl = "http://maps.google.com/maps?saddr=latitude,longitude&daddr=latitude,longitude";
Intent navIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(navigationUrl));
startActivity(navIntent);
Rotation answered 17/4, 2018 at 2:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.