【问题标题】:React native GeoFencing geolib library反应原生 GeoFencing geolib 库
【发布时间】:2021-06-07 20:28:59
【问题描述】:

您好,我正在使用 @mauron85/react-native-background-geolocation' 来获取我当前的坐标,并使用 https://www.npmjs.com/package/geolib 库来检查我的位置是否在多边形内,我的代码如下所示

var tf = geolib.isPointInPolygon({ latitude: {lat: location.latitude}, longitude: {lng: location.longitude} }, [
    { latitude: 27.483871, longitude:  95.204824},
    { latitude: 27.484353, longitude: 95.195472},
    { latitude: 27.492926, longitude: 95.4932795 },
    { latitude: 27.492956, longitude: 95.177179 },

  ]);

然而 tf 总是假的,即使它在边界内但是当我硬编码我的位置(边界内的位置是真的)时,代码如下

var tf = geolib.isPointInPolygon({ latitude: 27.488464, longitude: 95.2020986 }, [
    { latitude: 27.483871, longitude:  95.204824},
    { latitude: 27.484353, longitude: 95.195472},
    { latitude: 27.492926, longitude: 95.4932795 },
    { latitude: 27.492956, longitude: 95.177179 },

  ]);

我尝试了其他库但失败了谁能帮我解决这个问题。

【问题讨论】:

    标签: react-native npm geofencing


    【解决方案1】:

    显然这是由空指针引起的。用 if else 语句修复它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-14
      • 2018-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-28
      • 2021-11-07
      • 2021-05-03
      相关资源
      最近更新 更多