Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Map Matching #659

Closed
2 of 4 tasks
ericrwolfe opened this issue Jan 20, 2018 · 8 comments
Closed
2 of 4 tasks

Add support for Map Matching #659

ericrwolfe opened this issue Jan 20, 2018 · 8 comments
Labels
feature New feature request.

Comments

@ericrwolfe
Copy link
Contributor

ericrwolfe commented Jan 20, 2018

The Map Matching API now supports a waypoints url parameter (Project-OSRM/osrm-backend#4732):

This adds a parameter to the match service plugin, &waypoints, that will allow users to specify which input coordinates should be treated as waypoints in the response. Current behavior is to treat all input coordinates as waypoints.

By setting waypoints=0,<coordinates.length-1>, the response will return a route with a single leg similar to a normal directions route, and will allow for turn-by-turn navigation along a custom route.

In theory, you should be able to start navigation with a custom route as with the following:

    private List<Point> positions() {
        List<Point> positions = new ArrayList<>();
        positions.add(Point.fromLngLat(-77.04331040382385,38.89538758172669));
        positions.add(Point.fromLngLat(-77.04320847988129,38.89538758172669));
        positions.add(Point.fromLngLat(-77.04312264919281,38.89538758172669));
        positions.add(Point.fromLngLat(-77.042977809906,38.89540010700381));
        positions.add(Point.fromLngLat(-77.04290270805359,38.895391756819286));
        positions.add(Point.fromLngLat(-77.0427793264389,38.895391756819286));
        positions.add(Point.fromLngLat(-77.04257011413574,38.89537923154069));
        positions.add(Point.fromLngLat(-77.04242527484892,38.89537088135372));
        positions.add(Point.fromLngLat(-77.04230189323425,38.89537088135372));
        positions.add(Point.fromLngLat(-77.04201757907867,38.895362531165766));
        positions.add(Point.fromLngLat(-77.04189419746399,38.89536670625987));
        positions.add(Point.fromLngLat(-77.041717171669,38.89537505644734));
        positions.add(Point.fromLngLat(-77.04171180725098,38.89550030914138));
        positions.add(Point.fromLngLat(-77.04169571399689,38.89576751415038));
        positions.add(Point.fromLngLat(-77.04171180725098,38.89592616664882));
        positions.add(Point.fromLngLat(-77.04181909561157,38.89601384287748));
        positions.add(Point.fromLngLat(-77.04202830791473,38.896001317708574));
        positions.add(Point.fromLngLat(-77.04229652881622,38.89600549276512));
        positions.add(Point.fromLngLat(-77.04242527484892,38.89599296759476));
        positions.add(Point.fromLngLat(-77.0427417755127,38.895984617479954));
        positions.add(Point.fromLngLat(-77.04289734363556,38.895980442422186));
        positions.add(Point.fromLngLat(-77.04310655593872,38.895980442422186));
        positions.add(Point.fromLngLat(-77.04325139522551,38.895980442422186));
        positions.add(Point.fromLngLat(-77.04340696334839,38.895980442422186));
        positions.add(Point.fromLngLat(-77.04347133636475,38.89601384287748));
        positions.add(Point.fromLngLat(-77.04348742961884,38.8959011162779));
        positions.add(Point.fromLngLat(-77.0434820652008,38.89572158836101));
        positions.add(Point.fromLngLat(-77.04347670078278,38.8955838108147));
        positions.add(Point.fromLngLat(-77.04347670078278,38.89542933264189));
        positions.add(Point.fromLngLat(-77.04347133636475,38.89524980353237));
        positions.add(Point.fromLngLat(-77.04347133636475,38.89506192374576));
        positions.add(Point.fromLngLat(-77.04347133636475,38.89484481759551));
        positions.add(Point.fromLngLat(-77.04346060752869,38.894594309674424));
        positions.add(Point.fromLngLat(-77.04347133636475,38.89446070508852));
        positions.add(Point.fromLngLat(-77.0434820652008,38.89433545056098));
        positions.add(Point.fromLngLat(-77.0434820652008,38.894251947419924));
        positions.add(Point.fromLngLat(-77.0434820652008,38.894185144836364));
        positions.add(Point.fromLngLat(-77.0434820652008,38.89406406499353));
        positions.add(Point.fromLngLat(-77.0434820652008,38.893934634588426));
        positions.add(Point.fromLngLat(-77.04347670078278,38.89379685357545));
        positions.add(Point.fromLngLat(-77.04347670078278,38.89368412345691));
        positions.add(Point.fromLngLat(-77.04346597194672,38.89356304275993));
        positions.add(Point.fromLngLat(-77.04347133636475,38.893408560191695));
        positions.add(Point.fromLngLat(-77.04349279403685,38.893191448987274));
        positions.add(Point.fromLngLat(-77.04349279403685,38.89307454267923));
        positions.add(Point.fromLngLat(-77.04349279403685,38.89294511047088));
        positions.add(Point.fromLngLat(-77.04347670078278,38.892782276067265));
        positions.add(Point.fromLngLat(-77.04347670078278,38.89255263717129));
        positions.add(Point.fromLngLat(-77.04347670078278,38.89240232767372));
        positions.add(Point.fromLngLat(-77.04347670078278,38.89224366730341));
        positions.add(Point.fromLngLat(-77.04347670078278,38.89213928528757));
        positions.add(Point.fromLngLat(-77.04353034496307,38.89209335715199));
        positions.add(Point.fromLngLat(-77.04373955726624,38.892101707724315));
        positions.add(Point.fromLngLat(-77.04388439655304,38.892101707724315));
        positions.add(Point.fromLngLat(-77.0440775156021,38.89209335715199));
        positions.add(Point.fromLngLat(-77.04427063465118,38.89208500657868));
        positions.add(Point.fromLngLat(-77.04444766044617,38.89208500657868));
        positions.add(Point.fromLngLat(-77.04469442367554,38.892105883010096));
        positions.add(Point.fromLngLat(-77.04489827156067,38.892101707724315));
        positions.add(Point.fromLngLat(-77.04491972923279,38.89215181113758));
        positions.add(Point.fromLngLat(-77.04491972923279,38.89239815240535));
        positions.add(Point.fromLngLat(-77.04491972923279,38.8924983587783));
        positions.add(Point.fromLngLat(-77.04493045806885,38.892644492818775));
        positions.add(Point.fromLngLat(-77.04491972923279,38.89277810082123));
        positions.add(Point.fromLngLat(-77.04491972923279,38.89287830665815));
        positions.add(Point.fromLngLat(-77.04491972923279,38.893045316072154));
        positions.add(Point.fromLngLat(-77.04491436481476,38.89316222242831));
        positions.add(Point.fromLngLat(-77.04491436481476,38.89324572685059));

        return positions;
    }

    private void startNavigation(List<Point> positions) {
        MapboxMapMatching client = MapboxMapMatching.builder()
                .accessToken(Mapbox.getAccessToken())
                .profile(MapMatchingCriteria.PROFILE_DRIVING)
                .coordinates(positions)
                .steps(true)
                .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
                .overview(DirectionsCriteria.OVERVIEW_FULL)
//                .waypoints(waypoints) // not currently supported. For a single leg, waypoints should be (0, positions.length - 1)
//                .roundaboutExits(true) // not currently supported
//                .voiceInstructions(true) // not currently supported
//                .bannerInstructions(true) // not currently supported
                .build();

        client.enqueueCall(new Callback<MapMatchingResponse>() {
            @Override
            public void onResponse(Call<MapMatchingResponse> call, Response<MapMatchingResponse> response) {
                String url = call.request().url().toString();
                MapMatchingMatching matching = response.body().matchings().get(0);
                
                // There should be a better way to convert MapMatchingMatching to DirectionsRoute
                DirectionsRoute route = new DirectionsRoute.Builder()
                        .distance(matching.distance())
                        .duration(matching.duration())
                        .geometry(matching.geometry())
                        .legs(matching.legs())
                        .weight(matching.weight())
                        .weightName(matching.weightName())
                        //.routeOptions(matching.routeOptions) // not supported
                        .build();

                NavigationViewOptions options = NavigationViewOptions.builder()
                        .shouldSimulateRoute(true)
                        .directionsRoute(route)
                        .build();
                NavigationLauncher.startNavigation(this, options);
            }

            @Override
            public void onFailure(Call<MapMatchingResponse> call, Throwable throwable) {
            }
        });
    }

However, as commented above, we'll need to update a few things in order for this to work (mostly in MAS):

  • Add a waypoints property to MapboxMapMatching.Builder
  • Add roundaboutExits, voiceInstructions, bannerInstructions to MapboxMapMatching.Builder
  • Find a better way to convert a MapMatchingMatching to a DirectionsRoute to pass into MapboxNavigation
  • Add an example to Mapbox Navigation for custom routing

cc @mapbox/navigation-android @cammace @coxchapman

@zugaldia
Copy link
Member

cc: @osana for visibility on any required MAS changes.

@cammace
Copy link
Contributor

cammace commented Jan 22, 2018

I opened individual tickets on what needs to happen in Mapbox Java to unblock this.

@ericrwolfe
Copy link
Contributor Author

Upstream tickets in Mapbox Java:

@ericrwolfe
Copy link
Contributor Author

This missing params were added to Mapbox Matching Builder in mapbox/mapbox-java#718

@Guardiola31337
Copy link
Contributor

This is being addressed in mapbox/mapbox-java#705

@Guardiola31337
Copy link
Contributor

This is being addressed in mapbox/mapbox-java#705

PR 👉 mapbox/mapbox-java#759

@Guardiola31337
Copy link
Contributor

Guardiola31337 commented Apr 2, 2018

mapbox/mapbox-java#759 and mapbox/mapbox-java#764 have been merged. Are we good to close here @danesfeder?

@danesfeder
Copy link
Contributor

@Guardiola31337 Yep, map matching support was released with MAS 3.0 🎉 mapbox/mapbox-java#774

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request.
Projects
None yet
Development

No branches or pull requests

5 participants