gpt4 book ai didi

flutter - 如何在 Flutter 上使 Google map 可拖动并将标记保持在屏幕中央?

转载 作者:行者123 更新时间:2023-12-03 08:03:05 33 4
gpt4 key购买 nike

如何配置google_maps_flutter在 Flutter 中,为了将标记保持在 map 的中心,同时用户拖动 map 并获得具有新纬度和经度的新位置,例如优步

enter image description here

最佳答案

将您的 GoogleMap 放入 Stack 中,然后将光标小部件放在 GoogleMap 顶部的 Center 中如下:

  Stack(
children: [
GoogleMap(),
Center(child: CursorrWidget()),
],
);

要计算光标的纬度和经度,请在通知 onCameraIdle 时调用此函数:

GoogleMap(
onCameraIdle: () {
LatLngBounds bounds = mapController.getVisibleRegion();
final lon = (bounds.northeast.longitude + bounds.southwest.longitude) / 2;
final lat = (bounds.northeast.latitude + bounds.southwest.latitude) / 2;
}
)

关于flutter - 如何在 Flutter 上使 Google map 可拖动并将标记保持在屏幕中央?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73320493/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com