在Android硬件上模拟GPS位置-React Native

时间:2018-08-24 07:40:58

标签: android react-native geolocation

我尝试使用“假GPS”等应用程序,并在开发人员选项中启用了“模拟位置”以模拟位置。我的位置在Google地图上已成功更改,但是react native geolocation.getCurrentPosition仍在返回我实际的真实位置。

此外,在不同的间隔后调用geolocation.getCurrentPosition时,我得到的响应带有相同的时间戳。是什么原因?

getLocation() {
navigator.geolocation.getCurrentPosition(
  position => {
    if (this.state.inRide === false) {
      console.log('setting start coord');
      this.setState(
        { startLat: position.coords.latitude, startLong: position.coords.longitude },
        () => this.afterStartLocationSuccess()
      );
    } else if (this.state.inRide === true) {
      console.log('setting end coord');
      this.setState(
        { endLat: position.coords.latitude, endLong: position.coords.longitude },
        () => this.afterEndLocationSuccess()
      );
    }
    console.log(position);
  },
  error => Alert.alert('Try again! GPS not working')
  // Not using third argument.
  // { enableHighAccuracy: false, timeout: 10000, maximumAge: 1000 }
);
}

这是控制台日志:

two geolocation calls, after different intervals

0 个答案:

没有答案