在Google扑扑的Google地图应用中绘制带有折线的路线时,如何缩小和设置相机动画 [英] How to zoom out and animate camera when a route with poly lines is drawn on my flutter Google maps app

查看:41
本文介绍了在Google扑扑的Google地图应用中绘制带有折线的路线时,如何缩小和设置相机动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

扑朔迷离的Google Maps应用在两点之间绘制了一条路线,但通常两点都无法显示在屏幕上,我希望用户能够看到这两个点,例如当用户选择自己的位置并且该应用绘制了路线时从他的位置到目的地,它应该是可见的并适合屏幕,希望它带有动画相机,以提供流畅的感觉,任何想法,请并感谢您

解决方案

您需要使用 CameraUpdate.newLatLngBounds()在屏幕上显示两个点.

示例用法:

  mapController.animateCamera(CameraUpdate.newLatLngBounds(LatLngBounds(西南:LatLng(从LocationLatLng.latitude< =到LocationLatLng.latitude?fromLocationLatLng.latitude:toLocationLatLng.latitude,从LocationLatLng.longitude< =到LocationLatLng.longitude?fromLocationLatLng.longitude:toLocationLatLng.longitude),东北:LatLng(从LocationLatLng.latitude< =到LocationLatLng.latitude?toLocationLatLng.latitude:fromLocationLatLng.latitude,从LocationLatLng.longitude< =到LocationLatLng.longitude?toLocationLatLng.longitude:fromLocationLatLng.longitude)),100),); 

您需要记住以下示例所用的条件.

'southwest.latitude< = northeast.latitude':不正确.

否则它将引发错误.

更新:

如果您查看基本方向,则会为每个方向提供特定的范围/范围方向

 北(+90)|(-180)西——— + ————东(+180)|南(-90) 

下面的例子southWest = Latlng(-7.12725588946924,159.14)实际上要比north更东边East = Latlng(70.0415297179124,24.855900000000005).

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

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

My flutter Google maps app draws a route between two points but often the two points dont fit on the screen, I want the user to able to see the two points, like when the user selects his location and the app draws the route from his location to his destination it should be visible and fit on the screen,hopefully with animate camera for smooth feel, any thoughts, please and thank you

解决方案

You need to use CameraUpdate.newLatLngBounds() for making two points visible within the screen.

sample usage :

mapController.animateCamera(
      CameraUpdate.newLatLngBounds(
          LatLngBounds(
                southwest: LatLng(
                    fromLocationLatLng.latitude <= toLocationLatLng.latitude
                        ? fromLocationLatLng.latitude
                        : toLocationLatLng.latitude,
                    fromLocationLatLng.longitude <= toLocationLatLng.longitude
                        ? fromLocationLatLng.longitude
                        : toLocationLatLng.longitude),
                northeast: LatLng(
                    fromLocationLatLng.latitude <= toLocationLatLng.latitude
                        ? toLocationLatLng.latitude
                        : fromLocationLatLng.latitude,
                    fromLocationLatLng.longitude <= toLocationLatLng.longitude
                        ? toLocationLatLng.longitude
                        : fromLocationLatLng.longitude)),100),
    );

you need to keep in mind following condition as used is sample above.

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

Otherwise it will throw Error.

Update :

If you look at the Cardinal Direction, there are specific bounds/ranges provided to each direction

             North (+90)
               |
(-180) West ———+——— East (+180)
               |
             South (-90)

For an example below southWest = Latlng(-7.12725588946924, 159.14) would actually be more East than northEast = Latlng(70.0415297179124, 24.855900000000005).

And zoom will go outside the bound i.e., to the east of the given point instead southwest. You can understand more about this box using this interative website https://boundingbox.klokantech.com/

above info after update is taken from https://github.com/Leaflet/Leaflet/issues/4919

这篇关于在Google扑扑的Google地图应用中绘制带有折线的路线时,如何缩小和设置相机动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆