# react-native-location-track

> A simple approach to log and track location using React Native.

Latest version **0.1.18** (published 2023-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-location-track
pnpm add react-native-location-track
yarn add react-native-location-track
bun add react-native-location-track
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.18 |
| Published | 2023-12-12 |
| First published | 2023-11-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ammar Jabakji |
| Maintainers | ammar.jabakji |
| Keywords | react-native, ios, android, Location, tracking |

## Links

- npm: https://www.npmjs.com/package/react-native-location-track
- Repository: https://github.com/ammarjabakji/react-native-location-track
- Homepage: https://github.com/ammarjabakji/react-native-location-track#readme
- Issues: https://github.com/ammarjabakji/react-native-location-track/issues
- npm.io page: https://npm.io/package/react-native-location-track

## Dependencies (4)

- [react](https://npm.io/package/react.md) 18.2.0
- [react-native](https://npm.io/package/react-native.md) 0.72.6
- [react-native-background-timer](https://npm.io/package/react-native-background-timer.md) ^2.4.1
- [react-native-geolocation-service](https://npm.io/package/react-native-geolocation-service.md) ^5.3.1

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 0.1.18 (latest) — 2023-12-12
- 0.1.17 — 2023-12-12
- 0.1.16 — 2023-12-08
- 0.1.15 — 2023-12-06
- 0.1.14 — 2023-12-05
- 0.1.13 — 2023-12-05
- 0.1.12 — 2023-11-29
- 0.1.11 — 2023-11-29
- 0.1.10 — 2023-11-29
- 0.1.9 — 2023-11-29
- 0.1.8 — 2023-11-29
- 0.1.7 — 2023-11-29
- 0.1.6 — 2023-11-29
- 0.1.5 — 2023-11-29
- 0.1.4 — 2023-11-28
- … 5 more at https://npm.io/package/react-native-location-track/versions

## README

# react-native-location-track

A simple React Native library for efficiently logging and tracking user locations in both foreground and background.

## Installation

```sh
npm install react-native-location-track

```

or

```sh

yarn add react-native-location-track
```

Required dependencies

```sh
npm install react-native-background-timer react-native-geolocation-service

```

or

```sh
yarn add react-native-background-timer react-native-geolocation-service
```

**On Android**

> 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.

add the following to the src/main/AndroidManifest.xml

```
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
```

**On iOS, you have to add the following to the Info.plist**

```
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app requires access to your location when in use to provide personalized recommendations.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app requires access to your location to track your activities.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app requires access to your location when in use Always.</string>
```

## Usage

Before running your app on iOS, make sure you have CocoaPods installed and run:

```
cd ios
pod install
```

Example: Logging and Tracking Coordinates

```js
import React, {useState} from 'react';
import {View, Text, StyleSheet, ScrollView} from 'react-native';
import LocationTracker from 'react-native-location-track';

const App = () => {
  const [locationList, setLocationList] = useState([]);

  const handleLocationUpdate = ({latitude, longitude, appState}) => {
    const newLocationEntry = `${latitude}, ${longitude} (${appState})`;
    console.log('newLocationEntry', newLocationEntry);
    setLocationList(prevList => [...prevList, newLocationEntry]);
  };

  const locationTrackerConfig = {
    interval: 5000, // milliseconds
  };

  return (
    <View style={styles.container}>
      <ScrollView style={styles.scrollView}>
        {locationList.map((entry, index) => (
          <Text key={index}>{entry}</Text>
        ))}
      </ScrollView>
      <LocationTracker
        onLocationChanged={handleLocationUpdate}
        config={locationTrackerConfig}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    marginTop: 100,
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  scrollView: {
    flex: 1,
    width: '100%',
  },
});

export default App;
```

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

## License

MIT

---

---
_Source: https://npm.io/package/react-native-location-track · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
