mapbox-navigation-android
mapbox-navigation-android copied to clipboard
Android Drop-In UI: Is it possible to set the camera to different location and the zoom level
Hello Team,
I am using DropInUI for my application. The DropInUi always sets to my current location. In my app, I have multiple parking location for a particular order and I want to set the camera to the parking locations instead of my current location. I have tried the below code for setting the camera. But it always sets to my current location.
binding.navigationView.registerMapObserver(object : MapViewObserver() {
override fun onAttached(mapView: MapView) {
myMapView = mapView
viewAnnotationManager = mapView.viewAnnotationManager
mapboxMap = mapView.getMapboxMap()
}
override fun onDetached(mapView: MapView) {
}
})
private fun updateCamera(latLng: LatLng) {
val mapAnimationOptions = MapAnimationOptions.Builder().duration(1500L).build()
myMapView .camera.easeTo(
CameraOptions.Builder()
// Centers the camera to the lng/lat specified.
.center(Point.fromLngLat(latLng.longitude, latLng.latitude))
// specifies the zoom value. Increase or decrease to zoom in or zoom out
.zoom(15.5)
// specify frame of reference from the center.
.padding(EdgeInsets(500.0, 0.0, 0.0, 0.0))
.build(),
mapAnimationOptions
)
}
Mapbox Navigation SDK version: implementation 'com.mapbox.navigation:ui-app:2.8.0-rc.2' implementation 'com.mapbox.navigation:ui-dropin:2.8.0-rc.2'
Please check it and let me know how to solve this issue.
@Sridhar261990 Thank you for creating the ticket. I understand that you want to point the camera to a different location when you start the Drop-In UI. I have some following questions:
- Do you want to use this different location as the starting point for route request?
- Do you want Drop-in UI to allow you to transition camera to this locaation any time as desired?
Hi @abhishek1508 ,
Thanks for looking into this ticket.
Do you want to use this different location as the starting point for route request?
No I want to use my current location as my starting point. I have used annotation to display icons for parking(different) location. I want to start navigation from my current location when I tap the parking icons on the map. I have completed creating icons and clicking event. The only thing is setting camera to parking locations. So that the drivers can see the parking places without zoom out.
Do you want Drop-in UI to allow you to transition camera to this locaation any time as desired?
Yes.
Hi @abhishek1508, Is it something available already?
@Sridhar261990 We will be evaluating the possibility of achieving this with existing APIs and will come back to you with updates when we have them.
I think this won't be possible with the current release and we would have to expose additional APIs. However, we need a careful evaluation to be sure.
cc @Zayankovsky
@Sridhar261990 I tried your code (MapView.camera.easeTo
) and didn't have any problems with it, camera position was successfully updated regardless of current camera mode, even if I'm driving along the route in active guidance state. I guess I need more details from you to find out why it is not working for you.
@Zayankovsky Thank you for looking into this. I have uploaded the sample class file which I tried it in my app. I have only NavigationView in my xml. In my case, I am setting the camera inside the registerMapObserver where I get the mapView object.
<com.mapbox.navigation.dropin.NavigationView android:id="@+id/navigationView" android:layout_width="match_parent" android:layout_height="match_parent" app:accessToken="@string/mapbox_access_token" />
Please check it and let me know if you need any additional information.
@Zayankovsky Did you get a chance to look into the code?
@Sridhar261990 do you want to change initial camera position when using NavigationView
or do you want to change it later based on some user actions?
@Zayankovsky I want to set my initial camera position to the parking location and then I want to start the navigation when I click the parking icon. So again the camera should move to my current location and it should start the navigation.
This is not supported at the moment. As a workaround you can update camera position after a delay or use MapView.getMapboxMap().addOnMapIdleListener
. We will think of adding a proper solution for this request.
Thanks @Zayankovsky for doing the quick research. @Sridhar261990 We will try to address this soon hopefully in next couple of releases.
Thanks @Zayankovsky for the work around.
Thanks everyone for the work around! our fleet of drivers appreciates this a lot! Its a feature / tool they use on a regular basis.
We are satisfied with the work around provided based on our implementation.
@abhishek1508 you can close if required.
Thanks for the update. Closing the issue