Ich versuche, die Region Zustand von ComponentDidMount (oder render) -Funktion, aber es schlägt fehl. Weißt du, warum?Get-Status von ComponentDidMount schlägt fehl in React Native
Hier ist mein Code:
constructor(props) {
super(props);
navigator.geolocation.getCurrentPosition(
(position) => {
this.region = {
latitude: position.coords.latitude,
latitudeDelta: 0.005,
longitude: position.coords.longitude,
longitudeDelta: 0.005,
}
console.log("location from constructor:", this.region);
},
(error) => alert(error.message),
{enableHighAccuracy: true, timeout: 20000, maximumAge: 2000}
);
this.state = {
region: this.region
}
}
componentDidMount() {
console.log("location from componentDidMount:", this.state.region);
}
Hier meine Protokolle sind:
location from componentDidMount: undefined
location from constructor: Object {latitude: 48.8732, latitudeDelta: 0.005, longitude: 2.402855, longitudeDelta: 0.005}