Иногда Geolocation.getcurrentPosition получают некоторую ошибку ..
import React, {Component} from 'react';
import { Text, View, StyleSheet } from 'react-native';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
latitude: 'lat',
longitude: 'long',
}
}
componentDidMount() {
navigator.geolocation = require('@react-native-community/geolocation');
navigator.geolocation.getCurrentPosition(
(position) => {
this.setState({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
});
},
(error) => alert(error),
{ enableHighAccuracy: false, timeout: 200000, maximumAge: 1000 },
);
}
render(){
return (
<View style={styles.container}>
<Text style={styles.paragraph}>
{this.state.latitude}
</Text>
<Text style={styles.paragraph}>
{this.state.longitude}
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});
Это простой демонстрационный пример геолокации. Попробуйте это. И спросите, если какой-либо запрос.