How do I draw a route, along an existing road, between two points?

前端 未结 4 617
孤街浪徒
孤街浪徒 2020-11-27 03:18

I want to show the driving route between two locations in my android app. I want to draw the route only on top of road segments.

There are several answers on stack o

4条回答
  •  渐次进展
    2020-11-27 03:34

    You can use this library, and it's simple, check example of usage:

    Routing routing = new Routing.Builder()
        .travelMode(AbstractRouting.TravelMode.DRIVING)
        .withListener(this)
        .alternativeRoutes(true)
        .waypoints(start, end)
        .build();
    routing.execute();
    
    
    @Override
    public void onRoutingSuccess(List route, int shortestRouteIndex) {
        progressDialog.dismiss();
        CameraUpdate center = CameraUpdateFactory.newLatLng(start);
        CameraUpdate zoom = CameraUpdateFactory.zoomTo(16);
    
        map.moveCamera(center);
    
        if(polylines.size()>0) {
            for (Polyline poly : polylines) {
                poly.remove();
            }
        }
    
        polylines = new ArrayList<>();
        // Add route(s) to the map.
        for (int i = 0; i 

    And don't forget to add key using builder from example, if you getting warnings about keyless access (you should have billing account to use it with key)

提交回复
热议问题