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

NavigationView can draw route just once time. #624

Closed
1 task done
slm opened this issue Jan 2, 2018 · 8 comments
Closed
1 task done

NavigationView can draw route just once time. #624

slm opened this issue Jan 2, 2018 · 8 comments

Comments

@slm
Copy link

slm commented Jan 2, 2018

What kind of issue is this?

  • Question.
    Navigation SDK Version : 0.8.0
    MapBox Sdk : 5.2.1
    MapboxServices : 2.2.9
    MapboxSdkServices: 3.0.0-beta.1
    LocationLayerPlugin: '0.2.0'

NavigationView can draw route just once time. I used navigationView in a fragment in there.
I set route before show that fragment in activity with that setNavigation in that class.

getRoute

  Point origin = Point.fromLngLat(last_location.getLongitude(),last_location.getLatitude());
        Point destination = Point.fromLngLat(location.getLongitude(), location.getLatitude());
        NavigationRoute.builder()
                    .accessToken(Mapbox.getAccessToken())
                    .origin(origin)
                    .destination(destination)
                    .build()
                    .getRoute(this);
...
 @Override
    public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
        hideCalculatingDialog();
        if (response.body() != null) {
            if (response.body().routes().size() > 0) {

                DirectionsRoute route = response.body().routes().get(0);
                NavigationViewOptions.Builder optionsBuilder = NavigationViewOptions.builder();
                optionsBuilder.directionsRoute(route);
                optionsBuilder.navigationOptions(
                        MapboxNavigationOptions.builder()
                        .enableNotification(false)
                                .build());

                routeListener.onRouteCalculated(optionsBuilder.build());

            }
        }
    }

I add fragment in activity like that.

@Override
public void onRouteCalculated(NavigationViewOptions options) {
     NavigationUtils.setNavigation(this,options);
    getSupportFragmentManager()
         .beginTransaction()
         .remove(navigationFragment) // that navigationFragment use mapbox
         .commitAllowingStateLoss();
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.add(R.id.navigation_fragment_container, new 
    MapboxRouteNavigationFragment(),"NavigationRoute");
    transaction.commitAllowingStateLoss();
}
@danesfeder
Copy link
Contributor

Hey @slm is the issue here that you'd like to draw alternative routes in addition to the route being traveled when you begin navigation with NavigationView?

@slm
Copy link
Author

slm commented Jan 4, 2018

Hi @danesfeder
No. I am trying to explain with an example:
1-) I call setNavigation method(It's same NavigationLauncher.startNavigation but don't start activity) with route options from my location to B city. And show navigationview inside of fragment.

2-) After ı remove fragment from activity. And call setNavigation method again with route options my location to Z city.(I checked route options its correct) And show navigationview fragment. But navigation view show route from my location to B city.(First showed route) It's must be my location to Z city.

@danesfeder
Copy link
Contributor

@slm It looks like this may be an issue with your SharedPreferences being updated correctly the second time before you commit the Fragment again (just my hunch).

Can you verify that the second time the fragment is being added, the DirectionsRoute is the correct one here https://gist.github.com/slm/b78d15e203660b78bad2b31e171224d3#file-gistfile1-txt-L127?

@slm
Copy link
Author

slm commented Jan 6, 2018

@danesfeder I checked that issue a lot of times.

First request DirectionsRoute: {"distance":11951.7,"duration":1264.7,"geometry":"elyehAujyyr@U_@iKeP}Uy]....
Second request {"distance":3231.9,"duration":432.3,"geometry":"elyehAujyyr@U_@iKeP}Uy]eJr....

these route completely different. Map must show second route. But it's show first route.
I tried to commit instead of apply with SharedPreferences. apply runs asynchronous. But it could not fix this error.

@danesfeder
Copy link
Contributor

@slm It looks like this was an error involving the route extraction on our side. Once #640 lands, please see if your issue is resolved using the 0.8.1-SNAPSHOT cc @devotaaabel

@slm
Copy link
Author

slm commented Jan 11, 2018

I tested. Its works. Thank you.👍 But there a little bug. The first route marker is still visible.
screen shot 2018-01-11 at 22 42 03

@danesfeder
Copy link
Contributor

@slm Yeah we found that as well and will be addressed in #641 (we will clear existing markers on NavigationView#startNavigation)

@danesfeder
Copy link
Contributor

Closing this as the original issue was solved. Feel free to open any other issues as you run into them @slm. Thanks again for the feedback here.

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

No branches or pull requests

2 participants