reactnativecn / react-native-website

React Native 中文网
https://reactnative.cn
MIT License
216 stars 327 forks source link

expo-location手机无法定位 #757

Closed 3283615145 closed 8 months ago

3283615145 commented 8 months ago

以下代码安卓模拟器可以输出 console.log('ffffff',location),打包到手机后不输出是什么原因 代码

image

npx react-native info info Fetching system and libraries information... System: OS: Windows 10 10.0.19045 CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz Memory: 6.17 GB / 15.78 GB Binaries: Node: version: 18.17.1 path: D:\Software\Node\node.EXE Yarn: Not Found npm: version: 9.6.7 path: D:\Software\Node\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: Not Found IDEs: Android Studio: Not Found Visual Studio: Not Found Languages: Java: version: 11.0.15.1 path: C:\Program Files\Common Files\Oracle\Java\javapath\javac.EXE Ruby: Not Found npmPackages: "@react-native-community/cli": Not Found react: installed: 18.2.0 wanted: 18.2.0 react-native: installed: 0.72.4 wanted: ^0.72.4 react-native-windows: Not Found npmGlobalPackages: "react-native": Not Found Android: hermesEnabled: Not found newArchEnabled: Not found iOS: hermesEnabled: Not found newArchEnabled: Not found - 如果问题涉及到第三方包/库/模块,请也将package.json的内容粘贴到这里。 "@react-native-async-storage/async-storage": "^1.18.2", "@react-native-community/geolocation": "^3.1.0", "@react-navigation/bottom-tabs": "^6.5.8", "@react-navigation/native": "^6.1.7", "@react-navigation/stack": "^6.3.17", "babel-plugin-module-resolver": "^5.0.0", "expo": "~49.0.7", "expo-file-system": "~15.4.4", "expo-image-picker": "~14.3.2", "expo-location": "^16.3.0", "expo-module-scripts": "^3.0.11", "expo-permissions": "^14.4.0", "expo-status-bar": "~1.6.0", "opencage-api-client": "^1.0.2", "react": "18.2.0", "react-native": "^0.72.4", "react-native-amap-geolocation": "^1.2.3", "react-native-dropdown-picker": "^5.4.6", "react-native-geolocation-service": "^5.3.1", "react-native-gesture-handler": "^2.12.1", "react-native-modals": "^0.22.3", "react-native-render-html": "^6.3.4", "react-native-safe-area-context": "4.6.3", "react-native-screens": "~3.22.0", "react-native-swiper": "^1.6.0", "react-native-waterfall": "^0.0.8", "react-redux": "^8.1.2", "redux": "^4.2.1" 安卓打包到手机能正常定位

sunnylqm commented 8 months ago

输出到哪里? release后已脱离metro进程,只有通过adb logcat可以看到日志

3283615145 commented 8 months ago

手机上这两行代码没执行,我把console.log('ffffff',location)改成alert(('ffffff'+location)) image 通过adb logcat只看到一条关于react native相关 image

sunnylqm commented 8 months ago

alert也没执行的话,那么从代码逻辑上看,要么权限被拒了,从上面return了,要么有exception被catch了,从下面走了,上下都加上alert看呗?

3283615145 commented 8 months ago

模拟器和PC都是可以的,就放到真机不行,允许权限了 代码案例,能帮忙看看吗 https://docs.expo.dev/versions/latest/sdk/location/ image

sunnylqm commented 8 months ago

我上面已经看了啊

3283615145 commented 8 months ago

好的

sunnylqm commented 8 months ago

另外,不清楚expo-location是否依赖于gms框架,是的话那国内的机器肯定都用不了,可能陷入一种既不返回也不catch的阻塞状态

3283615145 commented 8 months ago

好的,如果这样的话还有什么其他办法实现定位吗

sunnylqm commented 8 months ago

gms不能用难道国内就没有别的地图了吗,要说到这个份上吗?