反应本机多边形位置

React Native Polygon Location

我正在开发一个移动应用程序,parent 可以在其中立即跟踪他们 child 的位置。我可以带child的瞬间position.The parent他离开黑区的时候会收到通知。大约有100个位置到达了这个黑色区域但是我不知道如何离开指定区域。我需要占据他们所有的位置并确定半径吗?而这个应用就是我的毕业设计

你的英语很好。不比我的差 ;)

您正在寻找的是一个函数,该函数 returns 一个布尔值,告诉您特定位置是否在多边形之外。

这个函数可以在 react-native-geo-fencing 包中找到。

你需要做的是这样的:

import GeoFencing from 'react-native-geo-fencing';


...
  const polygon = [
    { lat: 3.1336599385978805, lng: 101.31866455078125 },
    { lat: 3.3091633559540123, lng: 101.66198730468757 },
    { lat: 3.091150714460597,  lng: 101.92977905273438 },
    { lat: 2.7222113428196213, lng: 101.74850463867188 },
    { lat: 2.7153526167685347, lng: 101.47933959960938 },
    { lat: 3.1336599385978805, lng: 101.31866455078125 } // last point has to be same as first point
  ];

  navigator.geolocation.getCurrentPosition(
    (position) => {
      let point = {
        lat: position.coords.latitude,
        lng: position.coords.longitude
      };

      GeoFencing.containsLocation(point, polygon)
        .then(() => console.log('point is within polygon'))
        .catch(() => console.log('point is NOT within polygon'))
    },
    (error) => alert(error.message),
    { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
  );
...

此示例取自 react-native-geo-fencing 文档

希望这就是您要找的。