react-native-yometu-geolocation
v0.1.4
Published
Yometu Geolocation
Downloads
7
Readme
What is react-native-yometu-geolocation
react-native-yometu-geolocation is a library that used to build applications such as fitness, cycling, and other sports that require location updates and timers.
NOTE: Currently only available for iOS
Installation
npm install react-native-yometu-geolocation
// or
yarn add react-native-yometu-geolocation
1. Linking
YFor RN 0.60 or higher, no manual linking is needed. After installing the package, just run pod install from inside ios directory. It'll automatically pickup the package and install it.
2. Info.plist usage descriptions
Finally, you then need to make sure you have the correct usage discriptions inside your Info.plist
file. The message will show in the Alert box when your app requests permissions and lets the user know why you are asking for that permissions. They are also part of the App Store review process.
If you are only requesting "when in use" (foreground) location access you just need to make sure you have the NSLocationWhenInUseUsageDescription
item in your Plist.
If you are requesting "always" (background) permission you will also need to add NSLocationAlwaysAndWhenInUseUsageDescription
and NSLocationAlwaysUsageDescription
into your PList file.
The easiest way to add these is to find your Info.plist
in Xcode, right click on it, and then choose "edit as source code". You can then enter the items you need into the file:
<key>NSLocationWhenInUseUsageDescription</key>
<string>This is the plist item for NSLocationWhenInUseUsageDescription</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This is the plist item for NSLocationAlwaysAndWhenInUseUsageDescription</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This is the plist item for NSLocationAlwaysUsageDescription</string>
3. Background mode setup (optional)
For background location to work, a few things need to be configured:
In the Xcode project, go to Capabilities, switch on "Background Modes" and check "Location updates".
Set
NSLocationAlwaysAndWhenInUseUsageDescription
andNSLocationAlwaysUsageDescription
in yourInfo.plist
file.
Usage
import YometuGeolocation from "react-native-yometu-geolocation";
Get geolocation authorization
This method must be initialized at the beginning (before accessing the location)
YometuGeolocation.requestAuthorization();
Get Realtime Position
In this method you have 2 successful callbacks where one is for realtime location and the other is for getting the timer
// ...
const locationAuthorization = await YometuGeolocation.getPermissionStatus();
if (locationAuthorization.status) {
watchId = YometuGeolocation.watchLocation(
{
accuracy: 'highAccuracy',
allowBackground: true,
distanceFilter: 1,
withTimer: true,
},
(loc) => {
console.log('Watch Current Location ===>', loc);
},
(getTimer) => {
console.log('Watch Timer ====>', getTimer);
},
(err: any) => {
console.log('err watch location ===>', err);
}
);
} else {
// Triger if authorization denied
console.log(locationAuthorization.message);
}
Stop Realtime Position
// ...
YometuGeolocation.stopWatchLocation(watchId);
Paused Realtime Position
// ...
YometuGeolocation.pauseWatchLocation();
Resume Paused Realtime Position
// ...
YometuGeolocation.resumeWatchLocation();
Get Current Position
This method is used to get the location only occasionally when getting a certain action.
// ...
const locationAuthorization = await YometuGeolocation.getPermissionStatus();
if (locationAuthorization.status) {
YometuGeolocation.getLocation(
{
accuracy: 'highAccuracy',
cacheAge: 10000,
distanceFilter: 1,
timeout: 20000,
},
(loc) => {
console.log('Current Location ===>', loc);
},
(err: any) => {
console.log('err single location ===>', err);
}
);
} else {
console.log(locationAuthorization);
}
Accuracy Options
| Accuracy Value | Description | |-------------------|-----------------------------------------------------------------------------------------------| | bestForNavigation | The highest possible accuracy that uses additional sensor data to facilitate navigation apps. | | nearestTenMeters | Accurate to within ten meters of the desired target. | | hundredMeters | Accurate to within one hundred meters. | | kilometer | Accurate to the nearest kilometer. | | threeKilometers | Accurate to the nearest three kilometers. | | reduced | The level of accuracy used when an app isn’t authorized for full accuracy location data. | | highAccuracy | The best level of accuracy available. |
Troubleshooting
You must enable swift support in your project. Since the iOS implementation is written in swift, you need to add swift support in your project. It can be done just by adding an empty swift file and a bridging header in your project folder. You have to do it from xcode, otherwise swift compiler flag won't be updated.
1. Create empty swift file in your project with XCode
2. Click next button, then save your empty file
3. XCode will ask you "Create Bridging Header".
You can choose "Create Bridging Header", after that rebuild your code, and everything works normally.
This issue is caused by an update to the "Flipper-Folly" pod-spec. If you'd like to keep Flipper enabled, you can override the version in your Podfile:
Open your Podfile in your iOS project and change these lines of codes
# use_flipper! --> Change this to
use_flipper!({ 'Flipper-Folly' => '2.3.0' }) # Update this part
post_install do |installer|
flipper_post_install(installer)
end
You will need to update your pods by running
pod update
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT