
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
react-native-geolocation-service
Advanced tools
React native geolocation service for iOS and android
The react-native-geolocation-service package provides a simple and consistent API for accessing the device's geolocation capabilities. It is designed to be a drop-in replacement for the deprecated navigator.geolocation API in React Native, offering more reliable and accurate location data.
Get Current Position
This feature allows you to get the current position of the device. The code sample demonstrates how to use the getCurrentPosition method to retrieve the device's current location with high accuracy.
```javascript
import Geolocation from 'react-native-geolocation-service';
Geolocation.getCurrentPosition(
(position) => {
console.log(position);
},
(error) => {
console.error(error);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
);
```
Watch Position
This feature allows you to continuously watch the device's position. The code sample demonstrates how to use the watchPosition method to start watching the device's location and how to stop watching using the clearWatch method.
```javascript
import Geolocation from 'react-native-geolocation-service';
const watchId = Geolocation.watchPosition(
(position) => {
console.log(position);
},
(error) => {
console.error(error);
},
{ enableHighAccuracy: true, distanceFilter: 0, interval: 5000, fastestInterval: 2000 }
);
// To stop watching position
Geolocation.clearWatch(watchId);
```
Stop Observing Position
This feature allows you to stop all ongoing location observations. The code sample demonstrates how to use the stopObserving method to stop any active geolocation tracking.
```javascript
import Geolocation from 'react-native-geolocation-service';
Geolocation.stopObserving();
```
The react-native-location package provides a simple API for accessing the device's location services. It offers similar functionalities to react-native-geolocation-service, such as getting the current position and watching the position. However, it also includes additional features like requesting location permissions and checking the location services status.
The react-native-geolocation package is another alternative for accessing the device's geolocation capabilities. It provides a similar API to react-native-geolocation-service but is less actively maintained. It is a good option for basic geolocation needs but may lack some of the advanced features and reliability of react-native-geolocation-service.
The expo-location package is part of the Expo ecosystem and provides a comprehensive set of APIs for accessing the device's location services. It offers similar functionalities to react-native-geolocation-service, such as getting the current position and watching the position. Additionally, it includes features like geocoding, reverse geocoding, and background location tracking, making it a more feature-rich option for Expo users.
React native geolocation service for iOS and android.
This library is created in an attempt to fix the location timeout issue on android with the react-native's current implementation of Geolocation API. This library tries to solve the issue by using Google Play Service's new FusedLocationProviderClient
API, which Google strongly recommends over android's default framework location API. It automatically decides which provider to use based on your request configuration and also prompts you to change the location mode if it doesn't satisfy your current request configuration.
NOTE: Location request can still timeout since many android devices have GPS issue in the hardware/system level. Check the FAQ for more details.
yarn
yarn add react-native-geolocation-service
npm
npm install react-native-geolocation-service
RN Version | Package Version |
---|---|
>=0.60 | >=3.0.0 |
<0.60 | 2.0.0 |
<0.57 | 1.1.0 |
Since this library was meant to be a drop-in replacement for the RN's Geolocation API, the usage is pretty straight forward, with some extra error cases to handle.
One thing to note, for android this library assumes that location permission is already granted by the user, so you have to use
PermissionsAndroid
to request for permission before making the location request.
...
import Geolocation from 'react-native-geolocation-service';
...
componentDidMount() {
if (hasLocationPermission) {
Geolocation.getCurrentPosition(
(position) => {
console.log(position);
},
(error) => {
// See error code charts below.
console.log(error.code, error.message);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
);
}
}
async requestAuthorization(authorizationLevel) (iOS only)
Request location permission based on the authorizationLevel parameter. Can be either "whenInUse"
or "always"
. You have to configure the plist keys during setup.
When promise resolves, returns the status of the authorization.
disabled
- Location service is disabledgranted
- Permission granteddenied
- Permission deniedrestricted
- Permission restrictedgetCurrentPosition(successCallback, ?errorCallback, ?options)
successCallback: Invoked with latest location info.
errorCallback: Invoked whenever an error is encountered.
options:
Name | Type | Default | Description |
---|---|---|---|
timeout | ms | INFINITY | Request timeout |
maximumAge | ms | INFINITY | How long previous location will be cached |
accuracy | object | -- | { android: Link, ios: Link } If not provided or provided with invalid value, falls back to use enableHighAccuracy |
enableHighAccuracy | bool | false | Use high accuracy mode |
distanceFilter | m | 100 | Minimum displacement in meters |
showLocationDialog | bool | true | Whether to ask to enable location in Android (android only) |
forceRequestLocation | bool | false | Force request location even after denying improve accuracy dialog (android only) |
forceLocationManager | bool | false | If set to true , will use android's default LocationManager API (android only) |
watchPosition(successCallback, ?errorCallback, ?options)
successCallback: Invoked with latest location info.
errorCallback: Invoked whenever an error is encountered.
options:
Name | Type | Default | Description |
---|---|---|---|
accuracy | object | -- | { android: Link, ios: Link } If not provided or provided with invalid value, falls back to use enableHighAccuracy |
enableHighAccuracy | bool | false | Use high accuracy mode |
distanceFilter | m | 100 | Minimum displacement between location updates in meters |
interval | ms | 10000 | Interval for active location updates (android only) |
fastestInterval | ms | 5000 | Fastest rate at which your application will receive location updates, which might be faster than interval in some situations (for example, if other applications are triggering location updates) (android only) |
showLocationDialog | bool | true | whether to ask to enable location in Android (android only) |
forceRequestLocation | bool | false | Force request location even after denying improve accuracy dialog (android only) |
forceLocationManager | bool | false | If set to true , will use android's default LocationManager API (android only) |
useSignificantChanges | bool | false | Uses the battery-efficient native significant changes APIs to return locations. Locations will only be returned when the device detects a significant distance has been breached (iOS only) |
showsBackgroundLocationIndicator | bool | false | This setting enables a blue bar or a blue pill in the status bar on iOS. When the app moves to the background, the system uses this property to determine whether to change the status bar appearance to indicate that location services are in use. Users can tap the indicator to return to your app. (iOS only) |
clearWatch(watchId)
watchPosition
)stopObserving()
Stops observing for device location changes. In addition, it removes all listeners previously registered.
Name | Code | Description |
---|---|---|
PERMISSION_DENIED | 1 | Location permission is not granted |
POSITION_UNAVAILABLE | 2 | Location provider not available |
TIMEOUT | 3 | Location request timed out |
PLAY_SERVICE_NOT_AVAILABLE | 4 | Google play service is not installed or has an older version (android only) |
SETTINGS_NOT_SATISFIED | 5 | Location service is not enabled or location mode is not appropriate for the current request (android only) |
INTERNAL_ERROR | -1 | Library crashed for some reason or the getCurrentActivity() returned null (android only) |
Location timeout still happening ?
Try the following steps: (Taken from here)
Adjusting battery saver settings on different devices:
5.3.1 (September 23, 2022)
FAQs
React native geolocation service for iOS and android
The npm package react-native-geolocation-service receives a total of 100,835 weekly downloads. As such, react-native-geolocation-service popularity was classified as popular.
We found that react-native-geolocation-service demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.