Esempio n. 1
0
  /**
   * Generates a grid over the specified boundary's
   *
   * @param waypoints2 Array with the polygon points
   * @param angle Angle of the grid in Degrees
   * @param lineDist Distance between lines in meters
   * @return Returns a array of lines of the generated grid
   */
  private List<LineLatLng> generateGrid(List<LatLng> waypoints2, Double angle, Double lineDist) {
    List<LineLatLng> gridLines = new ArrayList<LineLatLng>();

    PolyBounds bounds = new PolyBounds(waypoints2);
    LatLng point = new LatLng(bounds.getMiddle().latitude, bounds.getMiddle().longitude);

    point = GeoTools.newpos(point, angle - 135, bounds.getDiag());

    // get x y step amount in lat lng from m
    Double y1 = Math.cos(Math.toRadians(angle + 90));
    Double x1 = Math.sin(Math.toRadians(angle + 90));
    LatLng diff =
        new LatLng(GeoTools.metersTolat(lineDist * y1), GeoTools.metersTolat(lineDist * x1));
    Log.d(
        "Diff",
        "Lat:"
            + GeoTools.metersTolat(lineDist * y1)
            + " Long:"
            + GeoTools.metersTolat(lineDist * x1));

    // draw grid
    int lines = 0;
    while (lines * lineDist < bounds.getDiag() * 1.5) {
      LatLng pointx = point;
      pointx = GeoTools.newpos(pointx, angle, bounds.getDiag() * 1.5);

      LineLatLng line = new LineLatLng(point, pointx);
      gridLines.add(line);

      point = GeoTools.addLatLng(point, diff);
      lines++;
    }

    return gridLines;
  }