Socket
Socket
Sign inDemoInstall

geofence

Package Overview
Dependencies
62
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    geofence

Geofencing for npm


Version published
Weekly downloads
19
decreased by-60.42%
Maintainers
1
Install size
8.52 MB
Created
Weekly downloads
 

Readme

Source

Geofence

Simple geofencing using Google or other geolocation providers's API

NPM NPM Downloads

  • Check the current location's distance/duration againts the destination
  • Caches the distances to reduce geolocation API calls
  • Accepts callbacks for finding current location
  • Accepts callbacks for when inside the fence

Screenshot

examples/cli.js

node cli.js --apiKey=$apiKey --destination="San Francisco, CA" --mode=driving --updateInterval=1 --fenceDurationValue=25

Output example

Installation

Install with npm:

npm install geofence --save

Usage

The current location and destination can be address or lat/long. See Google's Distance Matrix API


let options = {
  // You can get it from here: https://cloud.google.com/maps-platform/
  apiKey: "ENTER YOUR API HERE", // Enter your own api key
  updateInterval: 5,  // Update current location (in seconds)

  // API function to get the current location.
  // It should return a string that is an address or lat/long
  // See Google's Distance Matrix API:
  // https://developers.google.com/maps/documentation/distance-matrix/intro
  getCurrentLocation: getCurrentLocation,

  // Callback for when we are inside the fence (optional)
  insideGeofenceCallBack: insideGeofenceCallBack,

  // Callback function to be called whenever the 
  // current location and distance is updated (optional)
  updateDistanceCallBack: updateDistanceCallBack,

  loopForever: false,  // Stop/continue once we are inside the fence

  activateFenceOn: "duration", // 'duration' OR 'distance' OR 'either'
  fenceDurationValue: 25 * 60, // range of the fence in seconds
  fenceDistanceValue: 1000, // range of the fence in meters
};

let locationSepc = {
  destination: "Oakland, CA", // Can be address or lat/long
  mode: "driving" //
};
//-----------------------------------------------------------------------------
var geofence = require("geofence")(options, locationSepc);

geofence.start(options);

Examples

  • examples/example.js: Simple example
  • examples/cli.js: demonstrates running with command line arguments:
    • node cli.js --apiKey=YOUR_API_KEY --destination="San Francisco, CA"
  • examples/termux.js: demonstrates running inside Termux and Termux-API on Android using device GPS and system notifications. Run with:
    • node termux.js --apiKey=YOUR_API_KEY --destination="320 Main St, Venice, CA" --fenceDurationValue=300 --updateInterval=10
    • examples/termux_prompt.js: demonstrates running inside Termux and Termux-API on Android using device GPS and system notifications. It receives the inputs from command prompt:
    • node termux_prompt.js

Keywords

FAQs

Last updated on 23 Jul 2019

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc