我正在使用
mapbox_gl:-0.16.0
我的Flutter应用程序中的插件,当用户移动地图时(或移动结束后),我需要知道当前的缩放级别!但是,它始终返回原始缩放级别,而不是当前缩放级别。尽管如此,当我试图获得当前视口边界时,它会提供正确的坐标。如果有任何帮助,我将不胜感激。
我采用这种方法:
/* view code */
MapboxMap(
onMapCreated: (mController) {
// Assign the MapboxMapController instance to mapboxMapController
mapboxMapController = mController;
controller.onMapCreated(mController);
},
zoomGesturesEnabled: true,
accessToken:"<MAPBOX ACCESS TOKEN>",
initialCameraPosition: const CameraPosition(
target: LatLng(47.5973305239398, -107.06058413659325),
zoom: 15.0),
doubleClickZoomEnabled: true,
onCameraIdle: () {
controller.getView(mapboxMapController);
},
styleString: "mapbox://styles/mapbox/outdoors-v12",
)
/* view code */
...
/* controller code */
Future<void> getView(MapboxMapController mapboxMap) async {
mapboxMap.getVisibleRegion().then(
(bounds) async {
double northeastLat = bounds.northeast.latitude;
double northeastLng = bounds.northeast.longitude;
double northwestLat = bounds.northeast.latitude;
double northwestLng = bounds.southwest.longitude;
double southeastLat = bounds.southwest.latitude;
double southeastLng = bounds.northeast.longitude;
double southwestLat = bounds.southwest.latitude;
double southwestLng = bounds.southwest.longitude;
double zoomLevel = mapboxMap.cameraPosition!.zoom;
print(zoomLevel); // this always print 15.0, which is my intial zoom level
},
);
}
/* controller code */
大多数文档或示例代码都被告知要使用这个,但它对我不起作用!我已经查看了Mapbox Maps文档,但找不到实现此特定功能的明确示例。如有任何帮助或代码片段,我们将不胜感激。非常感谢。
mapboxMap.getCameraPosition().zoom;