【发布时间】:2020-11-19 17:48:53
【问题描述】:
我正在尝试渲染条件组件。我有带有该位置的 MapView,我想要实现的是:如果该位置是从用户授予的或找不到该位置,而不是 MapView,我想呈现一个 Textinput,用户可以在其中手动键入他们的位置。这是我的代码
export default class GpsLocation extends React.Component {
constructor(props) {
super(props);
this.state = {
region: null,
};
this._getLocationAsync();
}
_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
let location = await Location.getCurrentPositionAsync({
enableHighAccuracy: true,
});
let region = {
latitude: location.coords.latitude,
longitude: location.coords.longitude,
latitudeDelta: 0.0045,
longitudeDelta: 0.0045,
};
this.setState({ region: region });
};
render() {
if (this.status === "granted") {
return (
<View style={styles.locationContainer}>
<Text style={styles.note}>Adresa</Text>
<MapView
initialRegion={this.state.region}
showUserLocation={true}
showCompass={true}
rotateEnabled={false}
style={{ flex: 1, borderRadius: 10 }}
></MapView>
</View>
);
} else {
return (
<TextInput/>
);
}
}
}
【问题讨论】:
-
请说明您遇到的问题?
标签: reactjs react-native mobile