Flutter PositionStream未更新Map位置

3pmvbmvn  于 2022-11-17  发布在  Flutter
关注(0)|答案(1)|浏览(131)

我有一个Flutter应用程序,其中map显示user location
在模拟器上,当我更改coords时,标记会移动。
但是,在物理设备上,它根本不会移动。
我有一个地理定位器Stream来更新标记位置
这是我的代码

Position? currentPosition;
  StreamSubscription<Position>? positionStream;

  void listenToLocationChanges() {

    LocationIndicator locationIndicator = LocationIndicator();
    locationIndicator.locationIndicatorStyle = LocationIndicatorIndicatorStyle.pedestrian;

    final LocationSettings locationSettings = LocationSettings(
      accuracy: LocationAccuracy.high,
      distanceFilter: 100,
    );

    positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen(
      (Position? position) {
        print(position==null? 'Unknown' : '$position'); 
        

    currentPosition = position;

    GeoCoordinates geoCoordinates = GeoCoordinates (position!.latitude, position.longitude);
    bearing = position.heading;
    currentlat = position.latitude;
    currentlong = position.longitude;

    Location location = Location.withCoordinates(geoCoordinates);
    location.time = DateTime.now();
    location.bearingInDegrees = bearing;
   
    locationIndicator.updateLocation(location);

    _hereMapController.addLifecycleListener(locationIndicator);
    _locationIndicatorList.add(locationIndicator);

      },
    );
  }

当我改变自定义坐标时,它会在我的模拟器中工作,它更新得很好,但在设备上,它在打开时仍停留在该位置,这有什么原因吗?
先谢了

ckx4rj1h

ckx4rj1h1#

我更改了距离参数,现在是准确的

相关问题