Showing a route between two points with multiple waypoints

吃可爱长大的小学妹 提交于 2019-11-28 05:18:48

问题


I am new to android and developing a navigation based application for android.My question is I want to show a route with multiple way-points between source and destination node in Google maps and I don't know how to do it. I have search for this but most of the results are for two points.

Please help me to solve my problem

e.g:- when app user submits the destination with some way-points the map should display the route from the source to destination with those way-points on the phone.

Thanks !


回答1:


I don't think the Maps intent offers those capabilities, but you do have some other options

Better but more work 1)Create your own map activity that displays routes for multi-location(using a mapview and overlays). Here is an example of how to convert the kml file to a route

Quicker and Easier 2)Create a simple webview (or you can just intent a new one with a given url) and dynamically build the url for a google maps api request with waypoints. See Google's website for documentation on getting a map with routes via waypoints.




回答2:


"I have search for this but most of the results are for two points." You already found everything you need to do this.

For this, you're not "drawing through the waypoints along the way," you're actually going to have to draw a route between 2 points for each waypoint you have:

IE. You want to get from point A to point D, and on the way there are points B and C. The solution is to draw a route from A to B, B to C, and finally C to D.




回答3:


You can use the map intent like this:

    String address = "http://maps.google.com/maps?daddr=" + "Latitude" + "," + "Longitude" + "+to:" +"Latitude" + "," + "Longitude";
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(address));                                                         
    startActivity(intent);

in this case the start point will be your current location and you can add as many intermediate points as you want using "+to:"



来源:https://stackoverflow.com/questions/11039647/showing-a-route-between-two-points-with-multiple-waypoints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!