Проверить, находится ли перед пользователем / пеленгом в mapbox - andorid - PullRequest
0 голосов
/ 26 мая 2020

Я просто хочу знать, есть ли способ уведомить пользователя, если есть маркер примерно в 100 метрах перед ним, и я имею в виду направление / градус пользователя впереди.

точно так же:

enter image description here

Или есть способ прикрепить верхнюю точку треугольного многоугольника к азимуту / градусу пользователя?

PS: Я создаю приложение для уменьшения трафика c.

Ответы [ 2 ]

0 голосов
/ 22 июня 2020

У меня была почти такая же проблема, но с набором 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);
}
...