颤音:地图摄像头位置不更新到新的Latlong

发布于 2025-02-06 18:46:37 字数 377 浏览 2 评论 0原文

我正在使用流构建器,该材料在几秒钟后发送API请求并提取坐标(LAT,LNG)。

我想在新提取坐标上更新地图位置(相机位置&标记)。

但是相机位置正在更新,而不是专注于新的坐标。 我的Google Map小部件位于Stream Builder内部,我们正在通过快照传递数据 例如latlng = latlng(snapshot.data ['lat'],snapshot.data ['lng']) to 标记:setMarker(Markers,MarkerId,latlng,latlng,),> & 初始cameraposition:cameraposition(目标:latlng,Zoom:9.0,)

I am using Stream Builder that sends api request after some seconds and fetch coordinates (lat, lng).

I want to update the map location (camera position & marker) on newly fetch coordinates.

But Camera position is updating and not focusing on new coordinates.
My google map widget is inside of stream builder and in which we are passing data through snapshot
e.g latlng = LatLng(snapshot.data['lat'],snapshot.data['lng']) to markers: SetMarker( markers, markerID, latlng, ), & initialCameraPosition: CameraPosition( target: latlng, zoom: 9.0, )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清秋悲枫 2025-02-13 18:46:37

Googlemaps flutter上的小部件确实具有属性initialcameraposition,但顾名思义,这只是一个初始值,如果您想在加载它后要更新地图,我建议您使用回调on mapcreated,您可以在其中使用控制器。动画到某个位置。

这样做会看起来像这样:

onMapCreated: (GoogleMapController controller) {
      controller.animateCamera(
        CameraUpdate.newCameraPosition(CameraPosition(
           target: LatLng(snapshot.data['lat'],
            snapshot.data['lng']),
             zoom: 12)));
      setState((){});
}

希望这会有所帮助! )

The GoogleMaps widget on Flutter does have the attribute initialCameraPosition but as the name says this is just an initial value, if you want to update the map once this has loaded i'd recommend the use of the callback onMapCreated, where you can use the controller to animate to a certain position.

Doing so would look something like this:

onMapCreated: (GoogleMapController controller) {
      controller.animateCamera(
        CameraUpdate.newCameraPosition(CameraPosition(
           target: LatLng(snapshot.data['lat'],
            snapshot.data['lng']),
             zoom: 12)));
      setState((){});
}

Hope this helps! ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文