mapbox / mapbox-navigation-android

Mapbox Navigation SDK for Android
https://docs.mapbox.com/android/navigation/overview/
Other
622 stars 319 forks source link

Navigation UI map doesn't zoom to origin on starting navigation in Android #4407

Open aryalprakash opened 3 years ago

aryalprakash commented 3 years ago

Mapbox UI Navigation Android SDK version: 1.5.1

Navigation UI map doesn't zoom to origin position on starting navigation. Voice instruction is heard, puck is seen but map doesn't zoom.

Screenshot 1

But after dragging map a bit and clicking on recenter button (that appears after dragging map), it zooms to origin position as as expected.

Screenshot 2

Here's a video demonstration of the issue. Video link

I'm opening this activity from a react-native app and getting route as intent string passed from rn app.

` package com.thegana.MapBoxDirections import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.mapbox.api.directions.v5.models.DirectionsRoute import com.mapbox.mapboxsdk.Mapbox import com.mapbox.navigation.core.MapboxNavigation import com.mapbox.navigation.ui.NavigationViewOptions import com.mapbox.navigation.ui.OnNavigationReadyCallback import com.mapbox.navigation.ui.listeners.NavigationListener import com.mapbox.navigation.ui.map.NavigationMapboxMap import com.mapbox.geojson.Point import android.location.Location; import com.mapbox.api.directions.v5.DirectionsCriteria import com.mapbox.api.directions.v5.models.RouteOptions import com.mapbox.geojson.LineString import com.mapbox.mapboxsdk.geometry.LatLng import com.mapbox.navigation.base.internal.extensions.applyDefaultParams import com.mapbox.navigation.core.directions.session.RoutesRequestCallback

import android.util.Log;

import com.thegana.R import kotlinx.android.synthetic.main.activity_embedded_navigation.*

class MapboxActivity : AppCompatActivity(), OnNavigationReadyCallback, NavigationListener { private lateinit var navigationMapboxMap: NavigationMapboxMap private lateinit var mapboxNavigation: MapboxNavigation private lateinit var routeString: String

private val route by lazy { getRoutes() }

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    Mapbox.getInstance(applicationContext, getString(R.string.mapbox_access_token))
    setContentView(R.layout.activity_embedded_navigation)
    navigationView.onCreate(savedInstanceState)
    navigationView.initialize(this)
}

override fun onLowMemory() {
    super.onLowMemory()
    navigationView.onLowMemory()
}

override fun onStart() {
    super.onStart()
    navigationView.onStart()
}

override fun onResume() {
    super.onResume()
    navigationView.onResume()
}

override fun onStop() {
    super.onStop()
    navigationView.onStop()
}

override fun onPause() {
    super.onPause()
    navigationView.onPause()
}

override fun onDestroy() {
    navigationView.onDestroy()
    super.onDestroy()
}

override fun onBackPressed() {
    // If the navigation view didn't need to do anything, call super
    if (!navigationView.onBackPressed()) {
        super.onBackPressed()
    }
}

override fun onSaveInstanceState(outState: Bundle) {
    navigationView.onSaveInstanceState(outState)
    super.onSaveInstanceState(outState)
}

override fun onRestoreInstanceState(savedInstanceState: Bundle) {
    super.onRestoreInstanceState(savedInstanceState)
    navigationView.onRestoreInstanceState(savedInstanceState)
}

override fun onNavigationReady(isRunning: Boolean) {
    if (!isRunning && !::navigationMapboxMap.isInitialized) {
        if (navigationView.retrieveNavigationMapboxMap() != null) {
            this.navigationMapboxMap = navigationView.retrieveNavigationMapboxMap()!!
            navigationView.retrieveMapboxNavigation()?.let { this.mapboxNavigation = it }

            val optionsBuilder = NavigationViewOptions.builder(this)
            optionsBuilder.navigationListener(this)
            optionsBuilder.directionsRoute(route)
            navigationView.startNavigation(optionsBuilder.build())  
        }
    }
}

override fun onNavigationRunning() {
    // Empty because not needed in this example
}

override fun onNavigationFinished() {
    finish()
}

override fun onCancelNavigation() {
    navigationView.stopNavigation()
    finish()
}

private fun getRoutes(): DirectionsRoute {
    routeString = intent.getStringExtra("routeString")
    return DirectionsRoute.fromJson(routeString)
}

companion object {
    private const val TAG = "MainActivity"
}

} `

I tried adding navigationView.startCamera() on onNavigationRunning but didn't work.

abhishek1508 commented 2 years ago

Thanks for using the Mapbox Navigation SDK for Android and being a valued customer.

Mapbox will be soon deprecating any support for v0 and v1 versions of the SDK. To facilitate this transition we’re launching a new drop-in UI component into v2, equivalent to the existing NavigationView v1 in its design goals, however with a more modern and customizable API.

We plan to launch this new drop-in UI component as a Developer Preview feature in April, as part of the v2.5 series. Since you are using NavigationView with v1, we’d love to hear your feedback so that we can incorporate it ahead of a GA release.

If you’re interested in having early access to the upcoming drop-in UI for v2 and its documentation, drop a comment on this ticket or send an email to abhishek.kejriwal@mapbox.com

/cc @zugaldia @AhmerKhan1