我正在使用来自“react-native-maps”的 MapView
我无法显示“showsMyLocationButton”,所以我正在实现我自己的。
我想在不使用 React Native 的地理定位的情况下执行此操作,因为我发现它比 react-native-maps propshowUserLocation 慢。我使用返回坐标的 onUserLocationChange 事件。但是,当触发 onUserLocationChange 事件并设置包含 userLocation 的状态时,它会自动更新区域,而无需我明确要求。
这是我的代码:
display_my_location(coordinate){
alert("region changed")
this.setState({
region: {
latitude: coordinate.latitude,
longitude: coordinate.longitude,
latitudeDelta: 0.004,
longitudeDelta: 0.004
},
});
}
setUserLocation(coordinate){
//alert("User location changed MAP SHOULDNT MOVE")
this.setState({
userLocation: {
latitude: coordinate.latitude,
longitude: coordinate.longitude,
latitudeDelta: 0.004,
longitudeDelta: 0.004
}
})
}
<MapView
style={styles.map}
showsMyLocationButton={true}
onUserLocationChange={locationChangedResult => this.setUserLocation(locationChangedResult.nativeEvent.coordinate)}
initialRegion={this.state.region_amon}
showsUserLocation={true}
region={this.state.region}
mapType={this.state.map_style}
showsCompass = {true}
showsMyLocationButton={true}
chacheEnabled={false}
zoomEnabled={true}
Run Code Online (Sandbox Code Playgroud)