所以我尝试关注this tutorial来观看我的用户'使用react-native-maps进行地理定位:
当我在手机上访问我的应用时,会显示文字"经度:"和"纬度:"但是他们旁边没有真正的价值观。我可以在进入应用程序时获得站立的地理位置,但我无法观看。我的代码如下:
import React, {Component} from 'react';
import {
View, Text
} from 'react-native';
import MapView from 'react-native-maps';
import { Marker } from 'react-native-maps';
export default class FindPotato extends Component {
constructor(props) {
super(props);
this.state = {
latitude: null,
longitude: null,
error: null,
};
}
componentDidMount() {
this.watchId = navigator.geolocation.watchPosition(
(position) => {
this.setState({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
error: null,
});
},
(error) => this.setState({ error: error.message }),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000, distanceFilter: 10 },
);
}
componentWillUnmount() {
navigator.geolocation.clearWatch(this.watchId);
}
render() {
console.log(this.watchId);
return (
<View style={{ flexGrow: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Latitude: {this.state.latitude}</Text>
<Text>Longitude: {this.state.longitude}</Text>
{this.state.error ? <Text>Error: {this.state.error}</Text> : null}
</View>
);
}
}