我正在使用react-native-maps 并使用react-native api 进行地理定位。当我通过 API 使用位置时,模拟器上返回的结果显示我在旧金山,而不是我所在的科罗拉多州丹佛市。是否有原因导致我的位置无法显示我所在的位置?
我运行该位置的函数
// Get current users locaiton on load
componentDidMount() {
navigator.geolocation.getCurrentPosition((position) => {
console.log(position);
let newLat = parseFloat(position.coords.latitude);
console.log("newLat", newLat);
let newLng = parseFloat(position.coords.longitude);
console.log("newLng", newLng);
// set region of user to lat and long position
// deltas set distance from marker (zoom) on map
this.setState({
region: {
latitude: newLat,
longitude: newLng,
latitudeDelta: 0.0250,
longitudeDelta: 0.0125
},
error: null
});
console.log(this.state);
},
// if error set state with error
(err) => {
console.log(err),
// set location accuracy on
// max time to find location in 5 sec
// max time to use cached location for phone 5 sec
{ timeout: 5000, maximumAge: 5000 };
}
);
// watch for changes and update location
this.watchId = navigator.geolocation.watchPosition((position) => {
console.log(position);
let newLat = parseFloat(position.coords.latitude);
console.log("newLat", newLat);
let newLng = parseFloat(position.coords.longitude);
console.log("newLng", newLng);
// set region of user to lat and long position
// deltas set distance from marker (zoom) on map
this.setState({
region: {
latitude: newLat,
longitude: newLng,
latitudeDelta: 0.0250,
longitudeDelta: 0.0125
},
error: null
});
console.log(this.state);
},
(err) => {
console.log(err),
// set location accuracy on
// max time to find location in 5 sec
// max time to use cached location for phone 5 sec
// distance before location called again 10 m
{ timeout: 5000, maximumAge: 5000, distanceFilter: 10 }
}
);
}
我在初始状态下预设的位置是:
this.state ={
region: {
latitude: 39.739236,
longitude: -104.990251,
latitudeDelta: 0.1000,
longitudeDelta: 0.0500
},
which is relatively closer than where the iOS simulator shows me at
有人遇到这个问题并知道如何解决吗?是反应本机正在运行的网络还是不应该从我的笔记本电脑网络位置拉出?
我查看了其他人是否遇到过这个问题:React Native iOS 中的地理定位如果您搜索地理位置错误的react-native ios,堆栈上的搜索仅显示6个结果...谷歌也没有多大帮助。
感谢您的帮助