在我的 flutter Google 地图应用程序上绘制带有折线的路线时,如何缩小相机并为相机设置动画

mac*_*ira 1 android dart flutter

我的 flutter Google 地图应用程序在两点之间绘制一条路线,但通常这两个点不适合屏幕,我希望用户能够看到这两个点,就像当用户选择他的位置并且应用程序从他的位置绘制路线时到了他的目的地,它应该是可见的并适合屏幕,希望有动画相机以获得流畅的感觉,任何想法,请,谢谢

Sah*_*ngh 6

您需要用于CameraUpdate.newLatLngBounds()使两个点在屏幕内可见。

\n\n

示例用法:

\n\n
mapController.animateCamera(\n      CameraUpdate.newLatLngBounds(\n          LatLngBounds(\n                southwest: LatLng(\n                    fromLocationLatLng.latitude <= toLocationLatLng.latitude\n                        ? fromLocationLatLng.latitude\n                        : toLocationLatLng.latitude,\n                    fromLocationLatLng.longitude <= toLocationLatLng.longitude\n                        ? fromLocationLatLng.longitude\n                        : toLocationLatLng.longitude),\n                northeast: LatLng(\n                    fromLocationLatLng.latitude <= toLocationLatLng.latitude\n                        ? toLocationLatLng.latitude\n                        : fromLocationLatLng.latitude,\n                    fromLocationLatLng.longitude <= toLocationLatLng.longitude\n                        ? toLocationLatLng.longitude\n                        : fromLocationLatLng.longitude)),100),\n    );\n
Run Code Online (Sandbox Code Playgroud)\n\n

您需要记住上面示例中使用的以下条件。

\n\n

\'southwest.latitude <= northeast.latitude\': is not true.

\n\n

否则会抛出Error。

\n\n

更新 :

\n\n

如果您查看基本方向,就会发现每个方向都有特定的界限/范围

\n\n
             North (+90)\n               |\n(-180) West \xe2\x80\x94\xe2\x80\x94\xe2\x80\x94+\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94 East (+180)\n               |\n             South (-90)\n
Run Code Online (Sandbox Code Playgroud)\n\n

对于下面的示例 \nsouthWest = Latlng(-7.12725588946924, 159.14) 实际上比 NorthEast = Latlng(70.0415297179124, 24.855900000000005) 更东。

\n\n

并且缩放将超出边界,即到给定点的东边而不是西南方。您可以使用此交互式网站https://boundingbox.klokantech.com/了解有关此盒子的更多信息

\n\n

以上更新后的信息取自https://github.com/Leaflet/Leaflet/issues/4919

\n