问题
I'm making a map for my campus and need help. Can anyone tell me how to add driving directions to a specific geopoint? I would like the user to click on a map icon on the map, bring them to a description page of that place, and then have the option to "route directions" Seems simple but I'm very new to Java and Android.
回答1:
There is no support in the Android SDK for driving directions, sorry.
回答2:
The easiest option would be to link out to the Google Maps application. The URL below will handle that.
Uri uri= Uri.parse( "http://maps.google.com/maps?saddr=" + startLocation.getLatitude() + "," + startLocation.getLongitude() + "&daddr="+mapItem.lat + "," + mapItem.lon );
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
mActivity.startActivity(intent);
Also check out this page for all the options in the maps url:
http://www.seomoz.org/ugc/everything-you-never-wanted-to-know-about-google-maps-parameters
回答3:
I did this for an app at work.
I think your best bet is to use a MapView and with a Canvas draw a route over it.
To get the route, as have been pointed out, there is no native way in the Android SDK. So I would go for a public web service that does this for you. In my case, I used Google Directions API: https://developers.google.com/maps/documentation/directions/
It will give you step by step navigation from and to coordinates you give it. Steps include coordinates for each point and descriptions (i.e. continue in Foo Street 100 meters and then turn right towards Bar Street). You can use that to paint the route over a MapView (connecting the dots with lines...) and show written (or even spoken) directions. Check the documentation.
It gives you a lot of points in turns and curves. So it will look good even in roundabouts.
That will do it if you need to do it in your app. This worked perfectly for me.
And of course, as atreat has shown, you can use public intents enabled for this from apps of thirds (Google Maps Navigation...).
来源:https://stackoverflow.com/questions/8619972/google-maps-android-how-do-i-add-driving-or-walking-directions-to-a-specific-ge