0.9.14 • Published 10 months ago

rn-calmgeo v0.9.14

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

rn-calmgeo

npm version MIT licensed npm downloads

A React Native Module wrapper for CalmGeo

Compatibility

iOSReact Native
>=17.0>=0.73.9

Installation

npm

npm install rn-calmgeo

iOS

cd ios
pod install

API

1. API List

RnCalmGeo

APIfunction
start(config: Config): Promisestart service
config(config: Config): Promiseconfig & restart service
stop(): Promisestop service
getCount(): Promiseget local record count
getLocation(): Promiseget current location (also save to local storage)
clear(): Promiseclear local storage
sync(): Promiseupload to server
registerListener(listener: Listener)regist location listener, return a unsubscriber function object () => void
isRunning(): Promisetrue if the service is running

2. Types

2.1 Config

fieldtypedescription
desiredAccuracyDesiredAccuracyDesired Accuracy
distanceFilternumberThe minimum distance (measured in meters) a device must move horizontally before an update event is generated.
disableSpeedMultiplierbooleanSet true to disable automatic speed-based distanceFilter elasticity.
speedMultipliernumberControls the scale of automatic speed-based distanceFilter elasticity.
stationaryRadiusnumberWhen stopped, the minimum distance the device must move beyond the stationary location for aggressive background-tracking to engage.
url?stringYour server url where you wish to HTTP POST locations to
token?stringBearer token
httpTimeoutnumberHTTP request timeout in milliseconds.
methodMETHODThe HTTP method.
autoSyncbooleanIf you've enabled HTTP feature by configuring an url, the plugin will attempt to upload each location to your server as it is recorded.
syncThresholdnumberThe minimum number of persisted records to trigger an sync action.
maxBatchSizenumberIf you've enabled HTTP feature by configuring an url and autySync: true, this parameter will limit the number of records attached to each batch.
maxDaysToPersistnumberMaximum number of days to store a geolocation in local storage.
fetchActivitybooleanSet true to fetch activity information.

2.2 Location

fieldtypedescription
idstringUUID
timestampstringISO-8601 UTC timestamp provided by the native location API.
isMovingbooleantrue if location was recorded while in the moving state.
coordsCOORDSlocation info
activityActivityactivity info

2.3 Coords

fieldtypedescription
latitudenumberlatitude
longitudenumberlongitude
accuracynumberaccuracy (m)
altitudenumberaltitude
altitudeAccuracynumberAccuracy of altitude (m)
ellipsoidalAltitudenumberellipsoidalAltitude
speednumberspeed (m/s)
speedAccuracynumberAccuracy of speed (m/s)
headingnumberheading (north: 0.0) (deg)
headingAccuracynumberAccuracy of heading (deg)
floornumberfloor
mockbooleantrue if the system generates the location using on-device software simulation.
externalbooleantrue if the system receives the location from an external accessory.

2.4 Listener

function (location: Location) void

2.5 DesiredAccuracy

  • BEST_FOR_NAVIGATION
  • BEST
  • TEN_METERS
  • HUNDRED_METERS
  • KILOMETER
  • THREE_KILOMETERS

2.5 Method

  • POST
  • PUT

2.6 Activity

fieldtypedescription
typeenumstill \| on_foot \| walking \| running \| in_vehicle \| on_bicycle \| unknown
confidencenumber0~100%

Sample

import {
  Config,
  desiredAccuracyEnum,
  requestMethodEnum,
  RnCalmGeo,
  type Location,
} from 'rn-calmgeo';

// config
const configJson: Config = {
  desiredAccuracy: desiredAccuracyEnum.enum.BEST_FOR_NAVIGATION,
  distanceFilter: 16,
  disableSpeedMultiplier: false,
  speedMultiplier: 3.1,
  stationaryRadius: 25.0,

  httpTimeout: 10000,
  method: requestMethodEnum.enum.POST,

  autoSync: true,
  syncThreshold: 12,
  maxBatchSize: 250,
  maxDaysToPersist: 7,
};

// App
export default function App() {
  const [loca, setLoca] = useState<Location | undefined>();

  useEffect(() => {
    RnCalmGeo.start(configJson).then((value: boolean) => {
      console.log('start', value);
    });

    const clean = RnCalmGeo.registerListener(location => {
        setLoca(location);
          console.log('getCount', value);
          setCount(value);
        });
    });

    return clean;
  }, []);

  return (
    <SafeAreaView style={styles.container}>
      <View style={styles.row}>
        <Button title="Stop" onPress={() => RnCalmGeo.stop()} />
        <Button title="Restart" onPress={() => RnCalmGeo.config(configJson)} />
        <Button title="Location" onPress={() => RnCalmGeo.getLocation()} />
      </View>

      <Text>Location: {JSON.stringify(loca, null, 2)}</Text>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    marginHorizontal: 20,
    flex: 1,
    alignItems: 'flex-start',
    justifyContent: 'flex-start',
    gap: 10,
  },
  row: {
    alignSelf: 'stretch',
    gap: 10,
    maxHeight: 40,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
  },
  button: {
    backgroundColor: 'blue',
  },
});

Sample Image

npm.io

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

0.9.14

10 months ago

0.9.12

10 months ago

0.9.11

10 months ago

0.9.10-a

10 months ago

0.9.10

10 months ago

0.9.9

10 months ago

0.9.8

10 months ago

0.9.7

10 months ago

0.9.6

10 months ago

0.9.5

10 months ago

0.9.4-a

10 months ago

0.9.4

10 months ago

0.9.3

11 months ago