I have a react native application (v0.42.0) and I'm trying to use Geolocation but when I navigator.geolocation the following:
Native module cannot be null.
Has anyone else ran into this issue or know how to diagnose the cause?
I have a react native application (v0.42.0) and I'm trying to use Geolocation but when I navigator.geolocation the following:
Native module cannot be null.
Has anyone else ran into this issue or know how to diagnose the cause?
It turns out that when using Cocoapods with React Native it is necessary to include RCTGeolocation in your Podfile:
pod 'React', :path => '../some/path/node_modules/react-native', :subspecs => [
'Core',
'RCTAnimation',
'RCTImage',
'RCTText',
'RCTWebSocket', # needed for debugging
'RCTLinkingIOS',
'ART',
'RCTPushNotification',
'RCTActionSheet',
'RCTGeolocation'
]
In addition to the RCTGeolocation entry in your Podfile, if you are still getting the same error, check the following:
Make sure that the RCTGeolocation project is included in your Xcode project. If not, add it; it's located at node_modules/react-native/Libraries/Geolocation/RCTGeolocation.xcodeproj
After adding the project, make sure to link to it too. Select the root project in the file explorer, select the correct target in TARGETS, then select the General tab. Because you've added the project in the previous step, you'll now be able to find and add libRCTGeolocation.a
Make sure you have:
pod 'react-native-geolocation', path: '../node_modules/@react-native-community/geolocation' in your pod file.