New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-geolocation-service

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-geolocation-service - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

4

CHANGELOG.md
# Changelog
### 1.1.0 (July 2, 2018)
- Added support for project wide gradle properties.
- Added support for tracking location update.
### 1.0.4 (April 20, 2018)
- Fix crash due to illegal callback invocation.
- Added `showLocationDialog` option to control whether to show location dialog if it is disabled.

@@ -1,29 +0,107 @@

import { NativeModules, Platform } from 'react-native';
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
const { RNFusedLocation } = NativeModules;
// eslint-disable-next-line import/no-mutable-exports
let Geolocation = global.navigator.geolocation;
const noop = () => {};
let subscriptions = [];
let updatesEnabled = false;
// TODO: add static type checker
const Geolocation = Platform.OS === 'ios' ? global.navigator.geolocation : {
setRNConfiguration: (config) => {}, // eslint-disable-line no-unused-vars
if (Platform.OS === 'android') {
const { RNFusedLocation } = NativeModules;
const LocationEventEmitter = new NativeEventEmitter(RNFusedLocation);
requestAuthorization: () => {},
Geolocation = {
setRNConfiguration: (config) => {}, // eslint-disable-line no-unused-vars
getCurrentPosition: async (success, error = noop, options = {}) => {
// Right now, we're assuming user already granted location permission.
RNFusedLocation.getCurrentPosition(options, success, error);
},
requestAuthorization: () => {},
watchPosition: (success, error = noop, options = {}) => { // eslint-disable-line no-unused-vars
// eslint-disable-next-line no-console
console.warn('watchPosition is not yet implemented');
},
getCurrentPosition: async (success, error = noop, options = {}) => {
if (!success) {
// eslint-disable-next-line no-console
console.error('Must provide a success callback');
}
clearWatch: (watchID) => { // eslint-disable-line no-unused-vars
// eslint-disable-next-line no-console
console.warn('clearWatch is not yet implemented');
}
};
// Right now, we're assuming user already granted location permission.
RNFusedLocation.getCurrentPosition(options, success, error);
},
watchPosition: (success, error = null, options = {}) => {
if (!success) {
// eslint-disable-next-line no-console
console.error('Must provide a success callback');
}
if (!updatesEnabled) {
RNFusedLocation.startObserving(options);
updatesEnabled = true;
}
const watchID = subscriptions.length;
subscriptions.push([
LocationEventEmitter.addListener('geolocationDidChange', success),
error ? LocationEventEmitter.addListener('geolocationError', error) : null
]);
return watchID;
},
clearWatch: (watchID) => {
const sub = subscriptions[watchID];
if (!sub) {
// Silently exit when the watchID is invalid or already cleared
// This is consistent with timers
return;
}
sub[0].remove();
const sub1 = sub[1];
if (sub1) {
sub1.remove();
}
subscriptions[watchID] = undefined;
let noWatchers = true;
for (let ii = 0; ii < subscriptions.length; ii += 1) {
if (subscriptions[ii]) {
noWatchers = false; // still valid subscriptions
}
}
if (noWatchers) {
Geolocation.stopObserving();
}
},
stopObserving: () => {
if (updatesEnabled) {
RNFusedLocation.stopObserving();
updatesEnabled = false;
for (let ii = 0; ii < subscriptions.length; ii += 1) {
const sub = subscriptions[ii];
if (sub) {
// eslint-disable-next-line no-console
console.warn('Called stopObserving with existing subscriptions.');
sub[0].remove();
const sub1 = sub[1];
if (sub1) {
sub1.remove();
}
}
}
subscriptions = [];
}
}
};
}
export default Geolocation;

6

package.json
{
"name": "react-native-geolocation-service",
"version": "1.0.4",
"version": "1.1.0",
"description": "React native geolocation service for iOS and android",

@@ -38,3 +38,5 @@ "main": "js/index.js",

"husky": "^0.14.3",
"lint-staged": "^4.0.3"
"lint-staged": "^4.0.3",
"react": "16.3.1",
"react-native": "0.55.4"
},

@@ -41,0 +43,0 @@ "lint-staged": {

@@ -30,5 +30,23 @@ # react-native-geolocation-service

If you have a different play service version than the one included in this library, use the following instead. But play service version should be `11+` or the library won't work.
If you've defined [project-wide properties](https://developer.android.com/studio/build/gradle-tips#configure-project-wide-properties) (recommended) in your root build.gradle, this library will detect the presence of the following properties:
```gradle
buildscript {...}
allprojects {...}
/**
+ Project-wide Gradle configuration properties
*/
ext {
compileSdkVersion = 25
targetSdkVersion = 25
buildToolsVersion = "25.0.2"
supportLibVersion = "25.0.1"
googlePlayServicesVersion = "11.0.0"
}
```
If you do not have *project-wide properties* defined and have a different play-services version than the one included in this library, use the following instead. But play service version should be `11+` or the library won't work.
```gradle
...

@@ -98,3 +116,3 @@ dependencies {

# API
#### `getCurrentPosition(successCallback, errorCallback, options)`
#### `getCurrentPosition(successCallback, ?errorCallback, ?options)`
- **successCallback**: Invoked with latest location info.

@@ -109,2 +127,15 @@ - **errorCallback**: Invoked whenever an error is encountered.

#### `watchPosition(successCallback, ?errorCallback, ?options)`
- **successCallback**: Invoked with latest location info.
- **errorCallback**: Invoked whenever an error is encountered.
- **options**:
- enableHighAccuracy (bool)
- distanceFilter (double)
- interval (millisecond)
- fastestInterval (millisecond)
- showLocationDialog (whether to ask to enable location in Android)
#### `clearWatch(watchId)`
- watchId (id returned by `watchPosition`)
Checkout [React Native documentation](https://facebook.github.io/react-native/docs/geolocation.html#reference) to see the list of available methods.

@@ -124,4 +155,4 @@

# TODO
- [ ] Implement `watchPosition` & `clearWatch` methods for android
- [ ] Implement `stopObserving` method for android
- [x] Implement `watchPosition` & `clearWatch` methods for android
- [x] Implement `stopObserving` method for android

@@ -128,0 +159,0 @@ # FAQ

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc