Flutter Geolocator().getCurrentPosition vs StreamSubscription<;职位>;飘飘然

Flutter Geolocator().getCurrentPosition vs StreamSubscription<;职位>;飘飘然,flutter,geolocation,location,Flutter,Geolocation,Location,我当前正在使用geologitor().getCurrentPosition获取用户当前位置。。。但是当我在构建一个应用程序时。。我想计算用户当前位置和她/他的房子之间的距离(例如)。。。但由于用户可以移动到任何地方,并在某个点停止。。我还想计算新的距离。。。所以路线是这样的 Home= A user first location= B user second location= C (so user move from B to C) 我需要知道从A到B和从A到C的位置 …所以我想问的是..

我当前正在使用
geologitor().getCurrentPosition
获取用户当前位置。。。但是当我在构建一个应用程序时。。我想计算用户当前位置和她/他的房子之间的距离(例如)。。。但由于用户可以移动到任何地方,并在某个点停止。。我还想计算新的距离。。。所以路线是这样的

Home= A
user first location= B
user second location= C (so user move from B to C)
我需要知道从A到B和从A到C的位置 …所以我想问的是..仅使用
geologitor().getCurrentPosition
就足够了,还是我还需要使用
StreamSubscription
来监听用户位置的更改? 这是我的密码

Geolocator()
          .getCurrentPosition(desiredAccuracy: LocationAccuracy.high)
          .then((Position position) {
        setState(() {
          _first = position;
        });
        _distanceCalculation(_first.latitude, _first.longitude);
      }).catchError((error) {
        print(error);
      });

如果我需要
StreamSubscription
来监听用户位置的变化,那么在我的代码中应用
StreamSubscription
的方式将发生变化

您需要使用
StreamBuilder
并在
Stream.map()中进行计算
-更多阅读,您是否有应用StreamSubscription和GetCurrentPosition的示例代码?如果我只使用
Geolocator()。GetCurrentPosition
,我已经为您提供了两个链接,这是不够的?因为就我而言。。如果用户位置和家之间的距离小于500米。。他们可以执行我的命令。。。如果没有,他们应该移动到另一个地方,以便执行我的命令
geologitor()。getPositionStream()
在您移动时为您提供所有位置的详细信息-更多信息: