我有一个MapView和一个标记。我异步请求用户当前位置并将区域p设置为地图。我每10秒钟更新一次市场位置。这会使该区域复位到p位置。为避免这种情况,我实现了onRigionChange,以便在更新市场状态时保留最后的区域。这可以工作,但会使地图中的导航非常有问题。滚动和更改地图中的区域无法正常工作。可能是onregionchange和region prop造成了死锁吗?您是否有解决此问题的想法?
componentDidMount() {
this._getLocationAsync();
}
_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
this.setState({
errorMessage: 'Permission to access location was denied',
});
}
let location = await Location.getCurrentPositionAsync({});
this.setState({ location });
this.setState({
region: {
latitude: location.coords.latitude,
longitude: location.coords.longitude,
latitudeDelta: 0.003,
longitudeDelta: 0.003,
},
});
}
state = {
location: null,
region:null,
errorMessage: null,
marker: {latitude: 0,longitude: 0},
};
<MapView style={styles.map}
showsUserLocation = {true}
onRegionChange={this.onRegionChange.bind(this)}
region={this.state.region} >
<MapView.Marker
coordinate={this.state.marker}
title={"title"}
description={"description"}/>
</MapView>