如何在本地地图上显示连续移动的汽车图标?

Sib*_*iti 7 javascript react-native react-native-android react-native-maps

我正在使用airbnb的react-native-maps库来开发我的用于android的本机应用程序.此应用程序在主页上显示地图和汽车图标.

它工作正常但是当汽车在行驶并且汽车坐标连续变化时,地图不能平滑地渲染.带有汽车图标的MapView标记沿着路径从一个点跳到另一个点.我的期望是在地图上显示连续移动的物体,就像它在谷歌地图上显示的那样.

这是我的代码:

this.state = {
  latitude: 22.55231,
  longitude: 88.56772,
  angle: 0
}

componentDidMount(){
  navigator.geolocation.getCurrentPosition(
    position => {
      let latitude = position.coords.latitude;
      let longitude = position.coords.longitude;
      let angle = position.coords.heading;
      this.setState({latitude, longitude, angle});
    },
    error => console.log(error),
    {
      // enableHighAccuracy: true
    }
  );

  navigator.geolocation.watchPosition(
    position => {
      let latitude = position.coords.latitude;
      let longitude = position.coords.longitude;
      let angle = position.coords.heading;
      this.setState({latitude, longitude, angle});
    },
    error => console.log(error),
    {
      // enableHighAccuracy: true
    }
  );  
}

getMapRegion(){
  return {
    latitude: this.state.latitude,
    longitude: this.state.longitude,
    latitudeDelta: 0.9271,
    longitudeDelta: ASPECT_RATIO * 0.9271
  }
}

render(){
  let angle = this.state.angle || 0; 
  return(
    <MapView style={styles.map}
      showUserLocation={true}
      followUserLocation={true}
      region={this.getMapRegion()}>
      <MapView.Marker 
        title={'Hi'}
        style={{
          transform: { rotate: `${angle}deg` },
          width: 20,
          height: 20
        }}
        image={require('../../../images/car-marker-2.png')}
        coordinate={{ latitude: this.state.latitude, longitude: this.state.longitude }}/>
    </MapView>
  );
}
Run Code Online (Sandbox Code Playgroud)

对此有任何帮助非常感谢.

sfr*_*ini 3

我相信汽车正在“跳跃”,因为这是 GPS 计算新坐标的时间,而您只是发送新坐标,但并没有缓解过渡。请记住,GPS 不会立即工作。

您可能想要对标记进行动画处理。请参阅此处的“动画标记位置”:https ://github.com/airbnb/react-native-maps