Hi all,
I build an app were I need a location tracking (for pedestrian). I searching a smooth way to way do this. I use watchPositionAsync, each time the position of user change, a function is called and on this function, I use animateToRegion with the new region in parametre and the time. That work well for the region, the camera track smoothly the user but the map does not load when I arrive in a new area unless I drag the map with finger movement.
there is a better way to do this? Or a method to fix the issue?
followUser = async () => {
try {
await Location.watchPositionAsync(GEOLOCATION_OPTIONS, this.locationChanged);
}
catch (error) {
let status = Location.getProviderStatusAsync();
if (!status.locationServicesEnabled) {
alert('Veuillez activer la géolocalisation de votre appareil.');
}
}
};
locationChanged = (location) => {
const region = {
longitude: location.coords.longitude,
latitude: location.coords.latitude,
latitudeDelta: BASIC_LATITUDE_DELTA,
longitudeDelta: BASIC_LONGITUDE_DELTA
};
this.goToRegion(region);
this.setState({ currentRegion: region });
};
goToRegion = (region) => {
this.map.animateToRegion(region,1000*2);
};
<MapView
initialRegion={this.state.currentRegion}
ref={ref => { this.map = ref; }}
showsUserLocation={true}
style={{ flex: 1 }}
customMapStyle={MAP_STYLE_SAM}
mapType={(this.state.switchValue) ? 'hybrid':'standard'}
provider='google'
onRegionChangeComplete={this.onMapMove}
loadingEnable={true}
moveOnMarkerPress={false}
onPress={this.pressOnMap}
>