项目作者: goparrot

项目描述 :
Google maps geometry utils for react-native
高级语言: Java
项目地址: git://github.com/goparrot/react-native-geometry-utils.git
创建时间: 2020-07-27T21:10:52Z
项目社区:https://github.com/goparrot/react-native-geometry-utils

开源协议:MIT License

下载


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

Pre-install

Native module for iOS is written in Swift.

If your app project does not contain any Swift code, a workaround can be a single empty .swift file and an empty bridging header.

You may try react-native-swift.

If you had problems installing this package for iOS and found some solutions please create an issue or a PR that updates the README.

Installation

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

Usage

  1. import {
  2. polygonContainsLocation,
  3. circleContainsLocation,
  4. computeDistanceBetween
  5. } from "@goparrot/react-native-geometry-utils";
  6. // ...
  7. const polygon = [
  8. { latitude: 0, longitude: 0 },
  9. { latitude: 0, longitude: 1 },
  10. { latitude: 1, longitude: 1 },
  11. { latitude: 1, longitude: 0 },
  12. { latitude: 0, longitude: 0 }, // last point has to be same as first point
  13. ];
  14. const cicle = {
  15. center: {
  16. latitude: 0,
  17. longitude: 0,
  18. },
  19. radius: 15742.949, // approximate radius of 0.1 degree in meters
  20. };
  21. const pointIn = {
  22. latitude: 0.1,
  23. longitude: 0.1,
  24. };
  25. const pointOut = {
  26. latitude: 0.2,
  27. longitude: -0.2,
  28. };
  29. await polygonContainsLocation(pointIn, polygon); // true
  30. await polygonContainsLocation(pointOut, polygon); // false
  31. await circleContainsLocation(pointIn, cicle); // true
  32. await circleContainsLocation(pointOut, cicle); // false
  33. await computeDistanceBetween(pointIn, pointOut); // 35162.86 meters

API

Interfaces

  1. interface LatLng {
  2. latitude: number;
  3. longitude: number;
  4. }
  5. interface Circle {
  6. center: LatLng;
  7. radius: number;
  8. }

Functions

  1. polygonContainsLocation(point: LatLng, polygon: LatLng[]): Promise<boolean>;
  2. circleContainsLocation(point: LatLng, circle: Circle): Promise<boolean>;
  3. 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