google-maps - 如何计算10米的当前位置变化?

标签 google-maps flutter dart geolocation latitude-longitude

如何计算10米的当前位置变化?动态更改10米。

我试过了Flutter上的location插件。但不能正常工作。
location.changeSettings(distanceFilter: 10,interval: 1000); // 10是米,但是位置每次都会更新。

如何计算,我需要知道如何计算。(因为我需要计算旅行时的等待时间)

if(currentLocation> previousLocation)// currentLocation应该大于10米

currentLication = previousLocation + 10 meters

最佳答案

我认为位置插件目前不提供此类功能,但是您可以使用onLocationChanged回调事件

location.onLocationChanged().listen((LocationData currentLocation) {
  // Use current location
});

它将返回您当前的位置,而不是您必须使用Haversine公式进行计算,请查看herehere的更多详细信息
a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)
c = 2 ⋅ atan2( √a, √(1−a) )
d = R ⋅ c 

dart code下面可以帮助您计算差异并获得下一个位置:
import 'dart:math' show cos, sqrt, asin;

double calculateDistance(LatLng l1, LatLng l2) {
  const p = 0.017453292519943295;
  final a = 0.5 -
      cos((l2.latitude - l1.latitude) * p) / 2 +
      cos(l1.latitude * p) *
          cos(l2.latitude * p) *
          (1 - cos((l2.longitude - l1.longitude) * p)) /
          2;
  return 12742 * asin(sqrt(a));
}

关于google-maps - 如何计算10米的当前位置变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60612783/

相关文章:

google-maps - 在 React babel 组件中使用谷歌地图 API

Flutter 缓慢滚动到动态 Listview 的底部

database - 我在这里缺少什么-现有数据库的Sqlite Flutter

android - 如何在 flutter 朔迷离的版本中删除调试横幅?

android - 在谷歌地图 v2 上绘制虚线而不是实线

android - 带 map 的 Kotlin (标记未显示)

dart - 没有镜像包的flutter中如何使用ByteData和ByteBuffer

flutter - 如何获取小部件的位置,以便在加载时定位另一个小部件

javascript - Google Maps API 检查标记是否存在于多个边界

flutter - 两个不同的 block 导致 "Bad state: Stream has already been listened to."