Socket
Socket
Sign inDemoInstall

@goparrot/react-native-geometry-utils

Package Overview
Dependencies
0
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @goparrot/react-native-geometry-utils

Google maps geometry utils for react native


Version published
Weekly downloads
50
increased by16.28%
Maintainers
2
Created
Weekly downloads
 

Readme

Source

@goparrot/react-native-geometry-utils

Google maps geometry utils for react native

This library is a clone of react-native-geo-fencing with several improvements.

Installation

npm install @goparrot/react-native-geometry-utils

Usage

import {
  polygonContainsLocation,
  circleContainsLocation,
  computeDistanceBetween
} from "@goparrot/react-native-geometry-utils";

// ...

const polygon = [
  { latitude: 0, longitude: 0 },
  { latitude: 0, longitude: 1 },
  { latitude: 1, longitude: 1 },
  { latitude: 1, longitude: 0 },
  { latitude: 0, longitude: 0 }, // last point has to be same as first point
];

const cicle = {
  center: {
    latitude: 0,
    longitude: 0,
  },
  radius: 15742.949, // approximate radius of 0.1 degree in meters
};

const pointIn = {
  latitude: 0.1,
  longitude: 0.1,
};

const pointOut = {
  latitude: 0.2,
  longitude: -0.2,
};

await polygonContainsLocation(pointIn, polygon); // true
await polygonContainsLocation(pointOut, polygon); // false
await circleContainsLocation(pointIn, cicle); // true
await circleContainsLocation(pointOut, cicle); // false
await computeDistanceBetween(pointIn, pointOut); // 35162.86 meters

API

Interfaces

interface LatLng {
  latitude: number;
  longitude: number;
}

interface Circle {
  center: LatLng;
  radius: number;
}

Functions

polygonContainsLocation(point: LatLng, polygon: LatLng[]): Promise<boolean>;

circleContainsLocation(point: LatLng, circle: Circle): Promise<boolean>;

computeDistanceBetween(from: LatLng, to: LatLng): Promise<number>;

Contributing

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

License

MIT

Keywords

FAQs

Last updated on 28 Jul 2020

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