React Native和iOS模拟器的地理位置错误
我正在使用react native maps并使用react native api进行地理定位。当我通过API使用位置时,模拟器上显示的是我在旧金山,而不是在我所在的CO的丹佛。我的位置无法显示我所在的位置,这有什么原因吗 运行位置的我的函数React Native和iOS模拟器的地理位置错误,ios,react-native,ios-simulator,apple-maps,react-native-maps,Ios,React Native,Ios Simulator,Apple Maps,React Native Maps,我正在使用react native maps并使用react native api进行地理定位。当我通过API使用位置时,模拟器上显示的是我在旧金山,而不是在我所在的CO的丹佛。我的位置无法显示我所在的位置,这有什么原因吗 运行位置的我的函数 // Get current users locaiton on load componentDidMount() { navigator.geolocation.getCurrentPosition((position) => {
// 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
},
这比我在iOS模拟器上看到的要近
有人遇到这个问题,知道如何解决吗?是react native正在运行的网络,还是应该从我的笔记本电脑网络位置拉过来
我已查看是否有其他人遇到此问题:
如果你在本地ios上搜索地理位置,堆栈上的搜索只会显示6个结果……谷歌也帮不了什么忙
感谢您的帮助这是iOS模拟器(和Android模拟器)上的正确行为。您可以更改每个站点上地理位置的模拟坐标,如下所示(由其他答案转述):
telnet
和geo-fix
命令
或者,您可以按照ashutosh pandey的建议在真实设备上进行测试。很有趣,感谢您让我知道如何解决此问题,以便我可以测试我的地理位置!这在ios上不起作用。无论发生什么情况,我仍然会获得当前位置。请重新启动模拟器以查看修改后的位置。