【问题标题】:How to construct polygon using geolocation as coordinate using Google S2 Library如何使用 Google S2 库将地理位置作为坐标构建多边形
【发布时间】:2017-10-24 16:04:11
【问题描述】:

我可以使用谷歌 S2 库构建矩形,但我无法使用谷歌 S2 库构建多边形,我尝试了不同的方法来创建多边形但无法创建,请您帮帮我。

我的代码是:

  Double point1_lat= 41.94621306986162;
    Double point1_long = -87.85629272460938;
    Double point2_lat= 41.91198644177823;
    Double point2_long = -87.84427642822266;
    Double point3_lat=  41.91173095014916;
    Double point3_long = -87.7804183959961;
    Double point4_lat= 41.94570235966688;
    Double point4_long = -87.75672912597656;
    Double point5_lat= 41.966893394601335;
    Double point5_long = -87.78900146484375;
    Double point6_lat= 41.97480631113838;
    Double point6_long = -87.84049987792969;
    Double check1 = 41.916585116228354;
    Double check2 = -87.736129760742194;

    // For point
    S2Point point1 = new S2Point(point1_lat, point1_long, 0);
    S2Point point2 = new S2Point(point2_lat, point2_long, 0);
    S2Point point3 = new S2Point(point3_lat, point3_long, 0);
    S2Point point4 = new S2Point(point4_lat, point4_long, 0);
    S2Point point5 = new S2Point(point5_lat, point5_long, 0);
    S2Point point6 = new S2Point(point6_lat, point6_long, 0);
    S2Point point7 = new S2Point(check1, check2, 0);

    List<S2Point> point = new ArrayList<S2Point>();
    point.add(point1);
    point.add(point2);
    point.add(point3);
    point.add(point4);
    point.add(point5);
    point.add(point6);

    System.out.println("***************  debug point 3 
      ****************" + point);

    S2PolygonBuilder polygonBuilder = new S2PolygonBuilder();
     S2Loop loop = new S2Loop(point);

     System.out.println("***************  debug point 4 
     ****************" );
     polygonBuilder.addLoop(loop);
     S2Polygon polygon = polygonBuilder.assemblePolygon();

    System.out.println("***************  debug point 5 
    ****************" );
    S2RegionCoverer coverer = new S2RegionCoverer();
    coverer.setMinLevel(12);
    coverer.setMaxLevel(12);
    coverer.setMaxCells(100);

    System.out.println("***************  debug point 6 
    ****************");


    S2CellUnion union = coverer.getCovering(polygon);

    System.out.println("***************  debug point 7 
     ****************");

【问题讨论】:

  • S2Builder 应根据文档使用,而不是 S2PolygonBuilder。

标签: java android python google-location-services google-latitude


【解决方案1】:

获取 S2Point 必须 你改变你的代码:

S2Point point1 = S2LatLng.fromDegrees(point1_lat, point1_long).toPoint();
//new S2Point(point1_lat, point1_long, 0);

【讨论】:

    猜你喜欢
    • 2018-04-07
    • 1970-01-01
    • 2015-08-08
    • 2021-05-29
    • 2017-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多