首页 > 解决方案 > 反应原生:反应原生地理定位

问题描述

我需要在 react-native 中获取位置。我用过@react-native-community/geolocation。当getCurrentPosition我们有选项时enableHighAccuracy

我的问题是当我在其中运行我的应用程序时,android emulator它必须更改为enableHighAccuracy: true.

但是当我运行它时device它不起作用并且必须更改为enableHighAccuracy : false

这是我的代码示例:

const callLocation = () => {
    setLoading(true);
    Geolocation.getCurrentPosition(position => {
      const { longitude, latitude } = position.coords
      setLoading(false);
      setRegion({ ...region, latitude, longitude });
    },
      error => console.log(error.message),
      { 
        timeout: 20000, 
        enableHighAccuracy: true, // must change to false when run on device
        maximumAge: 1000 },
    );
  }

也许你和我有同样的问题,我非常感谢你的帮助。

标签: androidreact-nativegeolocationandroid-emulator

解决方案


推荐阅读