检查是否在 mapbox 中的 user/bearing 前面 - android

Check if in front of user/bearing in mapbox - andorid

我只是想知道是否有办法通知用户是否有标记在他们前面.. 100 米处,我的意思是在用户的 bearing/degree 前面。

就像:

或者是否有办法将三角形多边形的顶点附加到用户的bearing/degree?

PS:我正在创建一个应用程序来减少流量。

您可以使用 http://turfjs.org/docs/#bearing

的 Mapbox Java SDK 端口

https://github.com/mapbox/mapbox-java/blob/master/docs/turf-port.md#measurement

https://github.com/mapbox/mapbox-java/blob/master/services-turf/src/main/java/com/mapbox/turf/TurfMeasurement.java#L56

https://github.com/mapbox/mapbox-java/search?q=TurfMeasurement.bearing&unscoped_q=TurfMeasurement.bearing

我遇到了几乎相同的问题,但有一个 POI 集合并以这种方式解决

Polygon sectorPolygon(@NonNull Point center, double radius,@FloatRange(from = -180, to = 180) double bearing1,@FloatRange(from = -180, to = 180) double bearing2 , @TurfConstants.TurfUnitCriteria String units) {
     List<Point> coordinates = new ArrayList<>();
     coordinates.add(center);
     coordinates.add(TurfMeasurement.destination(center, radius, bearing1, units));
     coordinates.add(TurfMeasurement.destination(center, radius, bearing2, units));
     coordinates.add(center);

     List<List<Point>> coordinate = new ArrayList<>();
     coordinate.add(coordinates);
     return Polygon.fromLngLats(coordinate);
 }

 FeatureCollection pointsWithinPolygon(FeatureCollection points, FeatureCollection polygons) {
     ArrayList<Feature> features = new ArrayList<>();
     for (int i = 0; i < polygons.features().size(); i++) {
         for (int j = 0; j < points.features().size(); j++) {
             Point point = (Point) points.features().get(j).geometry();
             boolean isInside = TurfJoins.inside(point, (Polygon) polygons.features().get(i).geometry());
             if (isInside) {
                 features.add( points.features().get(j));
             }
         }
     }
     return FeatureCollection.fromFeatures(features);
 }

void checkCustomPOIOnRoute(Location location, FeatureCollection poiCollection){
    double bearing=location.getBearing();
    Polygon sector=sectorPolygon(Point.fromLngLat(location.getLongitude(),location.getLatitude()),250, bearing-5,bearing+5,TurfConstants.UNIT_METRES);

    Feature sectorFeature = Feature.fromGeometry(sector);
    FeatureCollection sectorCollection= FeatureCollection.fromFeature(sectorFeature);
    
    FeatureCollection found=pointsWithinPolygon(poiCollection, sectorCollection);
}