首页 / 浏览问题 / 移动GIS / 问题详情
Android 做查询时提示"参数 geometry 不能为空"
19EXP 2024年05月11日

以下是查询的代码  

 private void QueryCode(double x, double y, String type, PointPositionBean.ZnfxListDTO bean) {

        mList.clear();
        final ProgressDialog progress = new ProgressDialog(getContext());
        QueryService service = new QueryService(Constant.BASE_MAP_URL);
        ServiceQueryParameter parameter = new ServiceQueryParameter();
        parameter.setQueryMapName("HJDY_YN");//查询地图的地图名称
        parameter.setQueryServiceName("map-YN/rest");//查询的服务的实例的服务名称
        parameter.setQueryLayerName("HJDY_All@YN");//查询的图层的名称

        //设置查询参数
//        parameter.setExpectRecordCount(1);//查询记录个数
        parameter.setQueryRecordStart(0);//查询记录的起始位置
        parameter.setQueryOption(QueryOption.GEOMETRY);//查询结果内容类型

        Point2D center = new Point2D();
        center.setY(y);
        center.setX(x);
        Point2D center2 = new Point2D();
        center2.setX(x+2.100000);
        center2.setY(y+0.00000001);


        Point2Ds point2Ds = new Point2Ds();
        point2Ds.add(center);
        point2Ds.add(center2);
        GeoLine geoPoint = new GeoLine(point2Ds);
        Log.e("XXXX", x + "");
        Log.e("XXXY", y + "");
        TrackingLayer trackingLayer = mMapControl.getMap().getTrackingLayer();
        GeoStyle pointStyle = geoPoint.getStyle();
        if (pointStyle == null)
            pointStyle = new GeoStyle();
        pointStyle.setMarkerSize(new Size2D(6, 6));
        pointStyle.setMarkerSymbolID(0);
        pointStyle.setLineColor(new Color(231, 8, 73));
        geoPoint.setStyle(pointStyle);
        trackingLayer.add(geoPoint, "point1");

        parameter.setQueryGeomety(geoPoint);
        parameter.setQueryBounds(geoPoint.getBounds());//设置查询范围
        service.setResponseCallback(new ResponseCallback() {
            @Override
            public void requestSuccess() {
                //销毁进度条显示框
                progress.dismiss();
                Toast.makeText(getContext(), "查询成功", Toast.LENGTH_LONG).show();
            }

            @Override
            public void requestFailed(String arg0) {
                //销毁进度条显示框
                progress.dismiss();

                Toast.makeText(getContext(), "查询失败", Toast.LENGTH_LONG).show();
                System.out.println("错误信息 " + arg0);
            }

            @Override
            public void receiveResponse(FeatureSet arg0) {
                double a = parameter.getQueryDistance();
                if (arg0 instanceof FeatureSet) {

                    FeatureSet featureSet = (FeatureSet) arg0;

                    if (arg0.moveFirst()) {
                        boolean isStart = true;
                        while (isStart) {
                            if (arg0.moveNext()) {
                                isStart = true;
                                ProjectItemBean itemBean = new ProjectItemBean();
                                try {

                                    String HJGKDYBM = featureSet.getString("HJGKDYBM");
                                    itemBean.setHJGKDYBM(HJGKDYBM);
                                    System.out.println("featureSet HJGKDYBM is " + featureSet.getString("HJGKDYBM"));
                                    mList.add(itemBean);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            } else {
                                isStart = false;
                            }
                        }
                        
                    }


                    if (mList.size() > 0) {
                        Collections.reverse(mList);
                        ShowControlUnitFragment showControlUnitFragment = new ShowControlUnitFragment(mList);
                        showControlUnitFragment.show(getChildFragmentManager(), "ShowControlUnitFragment");
                        showControlUnitFragment.setOnClickView(new ShowControlUnitFragment.OnClickSelectView() {
                            @Override
                            public void myItemClick(int idx) {
                               
                            }
                        });
                    } else {
                        showShort("暂无数据");
                    }
                }
            }

            @Override
            public void dataServiceFinished(String arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void addFeatureSuccess(int arg0) {

            }
        });

        //显示服务查询进度条,回调里面销毁
        progress.setMessage("服务查询中...");
        progress.show();
        try {
            // 查询
//            service.query(parameter, QueryMode.BoundsQuery);//使用范围查询
//            service.query(parameter, QueryMode.DistanceQuery);//使用距离查询
            service.query(parameter, QueryMode.SpatialQuery);//使用空间查询
//            service.query(parameter, QueryMode.SqlQuery);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

1个回答

空间查询要使用georegion,范围查询可以使用geopoint
3,685EXP 2024年05月11日
new GeoLine()  这个线对象不行吗?
使用geoline是可以的,注意查询模式要设置为相交
...