Я хочу получить доступ к значениям широты и долготы из navigator.geolocation.getCurrentPosition (). Как я хочу использовать его в моем погодном API. Поскольку я новичок в проекте, основанном на местоположении, пожалуйста, помогите мне, если я делаю неправильно
1.В файле App.js и в componentDidMount ()
constructor(props) {
super(props);
this.state = {
lat:null,
lon:null,
}
}
componentDidMount = async () => {
const {lat, lon} = this.state;
navigator.geolocation.getCurrentPosition((position) => {
this.setState({
lat: position.coords.latitude.toFixed(3),
lon: position.coords.longitude.toFixed(3)
})
// I get values here
console.log('LATITUDE', this.state.lat)
console.log('LONGITUDE', this.state.lon)
})
// I want latitude and longitude values here
// Here the values I get is null
console.log('LATITUDE', this.state.lat)
console.log('LONGITUDE', this.state.lon)
}
Я знаюзначения, которые я получаю, будут нулевыми, но как получить фактические значения из getCurrentPosition ()? Любые предложения высоко ценятся ... Заранее спасибо