Closed sakyoyuto closed 1 year ago
Do you have a listener to the camera position set up?
mapController.addListener(() {
final cameraPosition = mapController.cameraPosition;
print('camera move: $cameraPosition');
});
this works for us.
Thank you for your reply.
The same code is executed, but with the following results.
mapController!.addListener(() {
final cameraPosition = mapController!.cameraPosition;
print('camera move: $cameraPosition');
});
Returns the same value as the first.
flutter: camera move: CameraPosition(bearing: 0.0, target: LatLng(35.656554, 139.74777700000004), tilt: 0.0, zoom: 14.0)
flutter: map camera idle
flutter: camera move: CameraPosition(bearing: 0.0, target: LatLng(35.656554, 139.74777700000004), tilt: 0.0, zoom: 14.0)
flutter: camera move: CameraPosition(bearing: 0.0, target: LatLng(35.656554, 139.74777700000004), tilt: 0.0, zoom: 14.0)
flutter: map camera idle
flutter: camera move: CameraPosition(bearing: 0.0, target: LatLng(35.656554, 139.74777700000004), tilt: 0.0, zoom: 14.0)
I am currently using an iPhone 14 Pro.
Can you share your MapboxMap construction, onMapCreated function, and versions?
MapBox Version
mapbox_gl: ^0.16.0
MapBoxMap
MapboxMap(
accessToken: MapBoxConfiguration.token,
styleString: MapBoxConfiguration.style,
onMapCreated: (controller) {
controller.addListener(() {
print(controller.cameraPosition);
});
},
initialCameraPosition: const CameraPosition(
target: LatLng(35.656554, 139.747777),
zoom: MapDefaultConfig.zoom, // zoom = 14
),
compassEnabled: true,
onCameraIdle: () {
print('map camera idle');
},
myLocationEnabled: true,
myLocationRenderMode: MyLocationRenderMode.NORMAL,
myLocationTrackingMode: MyLocationTrackingMode.Tracking,
compassViewPosition: CompassViewPosition.TopLeft,
compassViewMargins: const Point(16, 240),
),
Thank you.
And which device/OS are you trying to run this on?
I would try moving the controller variable outside of the MapboxMap widget to its parent and using the onMapCreated function to set that parent variable. I believe the onMapCreated function only runs once, and even though you are adding a listener, it might not be persisting the changes within that variable. See this for a reference. See the onMapCreated function in this file. You can create a process that sets that parent variable and then creates the listener event. At least that's what we do, and it works.
Thank you for your cooperation.
trackCameraPosition: true,
We found the cause. I forgot to set trackingCameraPosition to true. I am very sorry...
Thank you again for your help. I will close this thread.
Hi. Thank you for the wonderful package.
I have one concern. The content of cameraPosition of MapBoxMapController is not updated even if the map is moved. Zoom, target, etc. are not updated as initialPosition.
If this is something that doesn't update, is there a way to get the map's center point and zoom?
Thank you.
My doctor