我正在使用react-native-maps並使用react-native api進行地理定位。當我通過api使用位置時,模擬器上顯示的內容顯示在舊金山,而不是位於我所在的丹佛。有沒有理由爲什麼我的位置不會顯示我在哪裏?使用React Native和iOS模擬器的錯誤地理位置
我的在運行位置
// 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
},
比所述iPhone模擬器顯示我相對更靠近任何人遇到這個問題,並知道如何解決它?這是反應 - 本地運行的網絡,還是不應該從我的筆記本電腦網絡位置拉?
我已經看過,看是否有人遇到了這個問題: Geolocation in React Native iOS 和堆棧中的搜索只顯示6分的結果,如果你搜索地理位置錯誤的反應,提供原生iOS ...谷歌是沒有多大幫助的。
感謝您的幫助
有趣的是,謝謝你讓我知道如何解決這個問題,所以我可以測試我的地理位置! –