@react-native-community/geolocation:NativeModule.RNCGeolocation 为空
我正在尝试在我的 React Native 应用程序(Ios、expo)上使用地理定位。我已经安装了react-native-community/geolocation,当我导入它时,我得到这个错误:
@react-native-community/geolocation:NativeModule.RNCGeolocation is null。
它要求我在项目根目录中运行“react-native link @react-native-community/geolocation”,但是当我这样做时,它会说:调用react-native link [packageName]已被弃用,有利于自动链接。
我不知道该怎么办了。谁能帮我解决这个问题吗?请
I'm trying to use Geolocation on my React Native app (Ios, expo). I have installed react-native-community/geolocation, and when I import it I get this erro:
@react-native-community/geolocation:NativeModule.RNCGeolocation is null.
It asks me to run "react-native link @react-native-community/geolocation" in the project root, but when I do it it says: Calling react-native link [packageName] is deprecated in favor of autolinking.
I do not know what to do anymore. Can anyone help me with this? Please
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 Expo,则可以使用Expo 中的位置。
但是如果你想使用@react-native-community/geolocation,从
react-native
0.60或更高版本开始,自动链接应该自动为您配置库。但如果使用react-native
0.59 或更低版本,则必须制作 手动安装 工作。If you are using Expo, you can use the Location from Expo.
But if you want to use the
@react-native-community/geolocation
, sincereact-native
0.60 or higher the autolinking should configure the library for you automatically. But if usereact-native
0.59 or lower, you must make a manual installation for iOS and Android when thereact-native link
doesn't work.建议:要清理缓存,请删除 node_module 文件夹,
npm cache clean
rm -rf node_modules
如果您有 android 文件夹
cd android && ./gradlew clean
然后在根项目目录上执行:
npm install
。但是,大多数情况下,您的 expo 中不包含此文件,因此您必须使用
expo prebuild
生成 android 和 IOS 文件夹。不要忘记在 android studio 中运行你的 android 文件夹来为你构建 gradle 并减轻你的压力。
Adviced: To clean cache, delete node_module folder,
npm cache clean
rm -rf node_modules
If you have android folder
cd android && ./gradlew clean
Then do an :
npm install
on your root project directory.However, Most of the times this doesnt come with your expo, so you have to generate the android and IOS folder using
expo prebuild
.Don't forget running your android folder in the android studio to build gradle for you and save you the stress.