如何在反应原生中创建实时跟踪?



谁能告诉我,如何在反应原生中创建实时跟踪?使用地理位置,反应原生地图或其他依赖项,我想制作像uber这样的跟踪驱动程序

希望您已经安装了 react-native-maps 并将必要的包添加到您的应用程序中。在componentDidMount((中使用下面给定的代码。每当您的位置发生变化时,都会调用以下给定的代码。它将为您提供更新的位置。在这里您还可以找到标题,您可以使用标题来显示车辆方向或路线。

this.watchId = navigator.geolocation.watchPosition(
(position) => {
this.locationPermission = true;
console.log('Watch Position response', position);
const { coordinate } = this.state;
const { latitude, longitude } = position.coords;
const newCoordinate = {
latitude,
longitude
};
if (Platform.OS === 'android') {
if (this.marker) { this.marker._component.animateMarkerToCoordinate(newCoordinate, 500); }
}
else {
coordinate.timing(newCoordinate).start();
}
this.setState({
marker: {
latlng: {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
}
},
heading: position.coords.heading,
})

);
},
(error) => this.setState({ error: error.message }),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000, distanceFilter: 10 },
);

最新更新