android 在 esri 地图上显示多点

android show multi point on esri map

我是 arcgis 环境的新开发人员,也是 android 开发人员。对于我的培训,我遵循了 arcgis 教程。我想在我的地图上添加多个点,但是当我尝试时,只有最后一个点出现在地图上。
我需要你的帮助来解决它。

这是我当前的代码:

 MapView mMapview;
  GraphicsLayer graphicsLayer = new GraphicsLayer();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hello_map);
        mMapview = (MapView) findViewById(R.id.map);
        mMapview.addLayer(graphicsLayer);

        SimpleMarkerSymbol sms = new SimpleMarkerSymbol(Color.RED,10, SimpleMarkerSymbol.STYLE.CIRCLE);

        MultiPoint multiPoint =  new MultiPoint();
        multiPoint.add(-5.2769,6.8169);
        multiPoint.add(-3.0195,8.7057);
        multiPoint.add(-0.0195,9.7057);


        int len = multiPoint.getPointCount();
        Graphic[] graphics = new Graphic[len];
        for(int i = 0; i<len; i++){
            Point pt = multiPoint.getPoint(i);
            graphics[i] = new Graphic(pt,sms);
           graphicsLayer.addGraphic(graphics[i]);
        }
        //graphicsLayer.addGraphics(graphics);
        Toast.makeText(getApplicationContext(),"Count "+graphicsLayer.getNumberOfGraphics(),Toast.LENGTH_LONG).show();

    }

使用 ArcGIS Runtime 10.2.4,您的代码对我来说工作正常,但我必须放大很远才能看到三个不同的点,因为如果您使用的是标准 ArcGIS 底图之一,坐标以米为单位。也许那是你的问题。如果这些值应该是经度和纬度,则必须投影它们,并且只能在初始化 MapView 之后执行此操作,这可以使用 OnStatusChangedListener 来完成。试试这个:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_hello_map);
    mMapview = (MapView) findViewById(R.id.map);
    mMapview.addLayer(graphicsLayer);

    final SimpleMarkerSymbol sms = new SimpleMarkerSymbol(
            Color.RED, 10, SimpleMarkerSymbol.STYLE.CIRCLE);

    final MultiPoint multiPoint =  new MultiPoint();
    multiPoint.add(-5.2769,6.8169);
    multiPoint.add(-3.0195,8.7057);
    multiPoint.add(-0.0195,9.7057);

    final int len = multiPoint.getPointCount();
    final Graphic[] graphics = new Graphic[len];
    mMapview.setOnStatusChangedListener(new OnStatusChangedListener() {
        public void onStatusChanged(Object source, STATUS status) {
            if (STATUS.INITIALIZED.equals(status)) {
                for (int i = 0; i < len; i++){
                    Point pt = multiPoint.getPoint(i);
                    pt = (Point) GeometryEngine.project(
                            pt.getX(),
                            pt.getY(),
                            mMapview.getSpatialReference());
                    graphics[i] = new Graphic(pt,sms);
                    graphicsLayer.addGraphic(graphics[i]);
                }
            }
        }
    });

    //graphicsLayer.addGraphics(graphics);
    Toast.makeText(getApplicationContext(),"Count "+graphicsLayer.getNumberOfGraphics(),Toast.LENGTH_LONG).show();

}

仅供参考,如果您愿意,您可以使用 MultiPoint 几何图形创建单个图形,而不是现在使用 Point 几何图形创建的三个图形。再一次,您需要将 MultiPoint 投影到地图的空间参考。