【问题标题】:how to find distance and time calculation between two location in flutter如何在颤动中找到两个位置之间的距离和时间计算
【发布时间】:2021-03-06 03:37:46
【问题描述】:

我有多个位置和当前位置,我想找到我当前位置与谷歌地图颤振的其他给定位置之间的距离。

请提供任何可以轻松计算时间和距离的方法或库。我正在使用此代码,但我找不到正确的距离。

double _coordinateDistance(lat1, lon1, lat2, lon2) {
var p = 0.017453292519943295;
var c = cos;
var a = 0.5 - c((lat2 - lat1) * p) / 2 +
    c(lat1 * p) * c(lat2 * p) * (1 - c((lon2 - lon1) * p)) / 2;
return 12742 * asin(sqrt(a));}

【问题讨论】:

    标签: flutter flutter-layout flutter-dependencies


    【解决方案1】:

    使用https://pub.dev/packages/flutter_locations_distance 包 将您的多个位置添加到 lat 和 lon 数组中并使用此代码

    for(int i=0;i<locCount;i++){ 
    double distance;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      distance = await FlutterLocationsDistance().distanceBetween(currentLat, 
    currentLon, lat[i], lon[i]);
    } on PlatformException {
      distance = -1.0;
    }
    }
    

    对于每个多个位置,您可以获得当前位置与其他位置之间的距离。

    要获取您当前的位置,请使用 https://pub.dev/packages/location 包。

    暂时可以使用https://pub.dev/packages/stop_watch_timer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-21
      • 1970-01-01
      • 1970-01-01
      • 2015-10-26
      • 2014-05-15
      • 2011-12-24
      相关资源
      最近更新 更多