如何计算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公式来计算它,请参阅here和here了解更多详细信息>
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));
}