state = {
mapRegion: null,
hasLocationPermissions: false,
locationResult: null,
location:null
};
componentDidMount() {
this._getLocationAsync();
}
_handleMapRegionChange = mapRegion => {
console.log(mapRegion);
this.setState({ mapRegion });
};
_getLocationAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
this.setState({
locationResult: 'Permission to access location was denied',
});
} else {
this.setState({ hasLocationPermissions: true });
}
let location = await Location.getCurrentPositionAsync({});
this.setState({ locationResult: JSON.stringify(location) });
// Center the map on the location we just fetched.
this.setState({mapRegion: { latitude: location.coords.latitude,
longitude:
location.coords.longitude, latitudeDelta: 0.0922, longitudeDelta: 0.0421
}});
};
render() {
return (
<View style={styles.container}>
{
this.state.locationResult === null ?
<Text>Finding your current location...</Text> :
this.state.hasLocationPermissions === false ?
<Text>Location permissions are not granted.</Text> :
this.state.mapRegion === null ?
<Text>Map region doesn't exist.</Text> :
<MapView
style={styles.container}
region={this.state.mapRegion}
onRegionChange={this._handleMapRegionChange}
/>
}
<MapView.Marker
coordinate={this.state.location}
title="My Marker"
description="Some description"
/>
{/* <Text>
Location: {this.state.locationResult}
</Text> */}
</View>
);
}
}
我想为当前位置添加mapview.marker。在这里,我正在获取具有当前纬度经度的mapview。现在,我想添加mapviewMarker 我尝试添加mapviewmarker,但是在由:AIRMapMarker管理的视图的属性“坐标”中出现错误,例如错误