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

问题描述 投票:0回答:1

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

我尝试过,在Flutter上使用location插件。但不能正常工作。

location.changeSettings(distanceFilter: 10,interval: 1000); // 10是米,但是位置每次都在更新。

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

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

currentLication = previousLocation + 10 meters
google-maps flutter dart geolocation latitude-longitude
1个回答
0
投票

我不认为位置插件目前不提供这种功能,但是您可以使用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));
}
© www.soinside.com 2019 - 2024. All rights reserved.