问题
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
回答1:
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]
回答2:
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.
回答3:
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);
来源:https://stackoverflow.com/questions/16459426/android-navigation-intent