Android GIS开发系列-- 入门季(5),这篇文章中,我们知道如何去查找要素。现在有一个需求,查找某点5000米范围的要素,那如何来做呢?首先我们需要在地图上画个5000米半径的圆,然后根据QueryParameters来查询相关要素。具体如下:

一、画个5000米半径的圆

1.确定中心点:centerPoint
2.半径为5000
3.将一个圆分为120个点(当然可以细分更多),比如第一个点角度为0,求出sin与cos值,再分别求出经度与纬度:

纬度= 中心点的纬度+半径*cos值*每米的纬度偏移量
经度= 中心点的经度+半径*sin值*每米的经度偏移量

相关代码如下 :

/纬度每米偏移量(存在误差)
    public static final double ONE_METER_OFFSET = 0.00000899322;
    //计算当前纬度时经度的偏移量
    public static double calcLongitudeOffset(double latitude) {
        return ONE_METER_OFFSET / Math.cos(latitude * Math.PI / 180.0f);
    }
    //获取一个圆
    private Polygon addGraphicCricle(Point centerPoint,double meter) {
        List<Point> points = new ArrayList<Point>();
        double sin;
        double cos;
        double lon;
        double lat;
        for (double i = 0; i < 120; i++) {
            //sin值
            sin = Math.sin(Math.PI * 2 * i / 120);
            //cos值
            cos = Math.cos(Math.PI * 2 * i / 120);
            //纬度= 中心点的纬度+半径*cos值*每米的纬度偏移量
            lat = centerPoint.getY() + meter*cos* ONE_METER_OFFSET;
            //经度= 中心点的经度+半径*sin值*每米的经度偏移量
            lon = centerPoint.getX() + meter *sin* calcLongitudeOffset(lat);
            Point p = new Point(lon,lat);
            points.add(p);
        }
        Polygon polygon = new Polygon();

        for (int i = 0; i < points.size(); i++) {
            if (i==0) {
                polygon.startPath(points.get(i));
            }else{
                polygon.lineTo(points.get(i));
            }
        }

        return polygon;
    }
View Code

相关文章:

  • 2021-12-10
  • 2021-08-18
  • 2021-10-17
  • 2022-12-23
猜你喜欢
  • 2021-10-20
  • 2022-12-23
  • 2021-08-29
  • 2021-10-24
  • 2021-12-05
  • 2022-12-23
相关资源
相似解决方案