npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-backgroundservice-location

v0.4.1

Published

Package for React-Native Android get location running background service

Downloads

7

Readme

react-native-backgroundservice-location

Package for React-Native Android get location running background service

Supported platforms

| Platform | Support | | -------- | -------------------------------------------------------- | | Android | #00b48a | | iOS | #ff0707 | | Web | #ff0707 | | Windows | #ff0707 |

Getting started

Install my-project with npm

  npm install react-native-backgroundservice-location --save

or

  yarn add install react-native-backgroundservice-location

Configuration and Permissions

Android

This package build using

  • "react-native": "0.72.1"
  • BackgroundserviceLocation_kotlinVersion=1.7.0
  • BackgroundserviceLocation_minSdkVersion=21
  • BackgroundserviceLocation_targetSdkVersion=31
  • BackgroundserviceLocation_compileSdkVersion=31
  • BackgroundserviceLocation_ndkversion=21.4.7075529
  • JavaVersion.VERSION_1_8
  • gradle:7.2.1

To request access to location, you need to add the following line to your app's => android/src/main/AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Usage/Examples

import * as React from 'react';

import { StyleSheet, View, Button } from 'react-native';
import {
  startLocationUpdates,
  stopLocationUpdates,
  getLocation,
  getUniqueId,
} from 'react-native-backgroundservice-location';

export default function App() {
  getLocation().addListener('onLocationUpdate', (locationMap) => {
    console.log('Received :', locationMap);
  });

  const getImei = () => {
    getUniqueId()
      .then((uniqueID) => {
        console.log(uniqueID);
      })
      .catch((error) => {
        console.error(error);
      });
  };

  return (
    <View style={styles.container}>
      <Button
        title="Start Location Updates"
        onPress={() =>
          startLocationUpdates(
            15000,
            'http://localhost:9951/api/BackgroundLocation/LocationLog',
            'suep'
          )
        }
      />
      <Button
        title="Stop Location Updates"
        onPress={() => stopLocationUpdates()}
      />
      <Button title="Get getUniqueId" onPress={() => getImei()} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  box: {
    width: 60,
    height: 60,
    marginVertical: 20,
  },
});

Check out the example project for more examples.

Methods

Details

startLocationUpdates

startLocationUpdates function to run the process for pulling location and running function in the background service.

(alias) startLocationUpdates(a: number, b: string): Promise import startLocationUpdates

This function need two parameter :

  1. Delay in milisecond (number), This delay is for how long it takes to process the location data pull.
  2. url API to save data feedback location into database. Can you create api in your localhost with endpoint =>
MethogetLocation
Body Request :
{
    "lat": "DOUBLE",
    "lon": "DOUBLE",
    "accuracy": "DOUBLE",
    "androiddate": "STRING",
    "uniqueID": "STRING",
    "userid": "STRING",
    "createdby": "STRING"
}
URL : http://{yoururl}/api/BackgroundLocation/LocationLog

Example Code from APIS

if you don't use the default function to send data to the database then fill it with "null"

Example :

startLocationUpdates( 1000, 'http://localhost:9951/api/BackgroundLocation/LocationLog','userID' )

or

startLocationUpdates(1000, null, null);

if the third parameter is null then it will default to string "system"

stopLocationUpdates

This function for stop / kill process in background service, no parameter.

getLocation

This function for get data location, provided that you have run the startLocationUpdates function.

Example :

getLocation().addListener('onLocationUpdate', locationMap => {
    console.log('Received :', locationMap);
    // your code for process data locationMap
  })

Object data :

{
 "accuracy": 1,
 "androiddate": "04-07-2023 14:21:03",
 "latitude": -7.257472,
 "longitude": 112.752088,
 "urlPost": null
}

getUniqueId

Gets the device unique ID

Example

const getImei = () => {
   getUniqueId()
     .then((uniqueID) => {
       console.log(uniqueID);
     })
     .catch((error) => {
       console.error(error);
     });
 };

Maintainers

This module is developed and maintained by Angga Putra.

I owe a lot to the fantastic React & React Native community, and I contribute back with my free time 👨🏼‍💼💻 so if you like the project, please star it ⭐️!

If you need any help with this module, or anything else, feel free to reach out to me! I provide boutique consultancy services for React & React Native. Just visit my website, or send me an email at [email protected] 🙏🏻

Contributing

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

License

The library is released under the MIT licence. For more information see LICENSE.