Надеюсь, вы установили реактивные карты и добавили необходимые пакеты в ваше приложение. Используйте приведенный ниже код в 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 },
);