无法使SpatialReference工作(ArcGIS)

时间:2016-09-25 08:10:15

标签: android arcgis

我一直试图让SpatialReference在ArcGIS中运行,无论我尝试什么,我都无法让它工作,任何帮助表示赞赏。 这是我的代码

wgs84 = SpatialReference.create(SpatialReference.WKID_WGS84);


    SimpleMarkerSymbol simpleMarker = new SimpleMarkerSymbol(Color.RED, 5,SimpleMarkerSymbol.STYLE.CIRCLE);


    Point pointGeometry = new Point(-35.238019 ,149.083404,0,SpatialReference.WKID_WGS84);
   /* Point pointGeometry = new Point(16596066.8,-3896170.7);*/

    Graphic pointGraphic = new Graphic(pointGeometry, simpleMarker);


    mGraphicsLayer.addGraphic(pointGraphic);

1 个答案:

答案 0 :(得分:0)

两个问题:

  1. 以正确的顺序指定坐标。无论何时指定坐标,都需要检查ArcGIS Runtime文档(10.2.xQuartz)以查看要使用的订单。创建Point时,首先指定X(经度),然后指定Y(纬度)。 149.083404不是有效的纬度,所以我认为你的意思是经度。切换它们。
  2. 除非文档说“经度”和“纬度”,否则假设地图坐标。这意味着你需要使用GeometryEngine.project将你的点投射到地图的空间参考,除非你打电话给方法的参数为longitudelatitude,而不是xy
  3. 我无法判断您是使用10.2.x还是使用Quartz Beta - 您使用的是每个元素 - 所以这是使用每个API的工作示例。

    Quartz(假设您已在布局XML中声明了MapView):

    public class MainActivity extends AppCompatActivity {
    
        private MapView mMapView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            mMapView = (MapView) findViewById(R.id.mapView);
            // ArcGISMap constructor takes latitude (Y) first
            ArcGISMap map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC,
                    -35.238019, 149.083404, 10);
            mMapView.setMap(map);
    
            GraphicsOverlay graphicsLayer= new GraphicsOverlay();
            mMapView.getGraphicsOverlays().add(graphicsLayer);
    
            SimpleMarkerSymbol simpleMarker = new SimpleMarkerSymbol(
                    SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 5);
            // Point constructor takes X (longitude) first
            Point pointGeometry = new Point(
                    149.083404, -35.238019, 0, SpatialReference.create(4326));
            Graphic pointGraphic = new Graphic(pointGeometry, simpleMarker);
            graphicsLayer.getGraphics().add(pointGraphic);
        }
    
        @Override
        protected void onPause(){
            mMapView.pause();
            super.onPause();
        }
    
        @Override
        protected void onResume(){
            super.onResume();
            mMapView.resume();
        }
    }
    

    10.2.x(假设您在布局XML文件中声明了MapView MapOptions}:

    public class MainActivity extends AppCompatActivity {
    
        private MapView mMapView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            mMapView = (MapView) findViewById(R.id.mapView);
    
            mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
                @Override
                public void onStatusChanged(Object o, STATUS status) {
                    if (STATUS.INITIALIZED.equals(status)) {
                        // MapOptions constructor takes latitude (Y) first
                        MapOptions mapOptions = new MapOptions(
                                MapOptions.MapType.TOPO, -35.238019, 149.083404, 10);
                        mMapView.setMapOptions(mapOptions);
    
                        GraphicsLayer graphicsLayer = new GraphicsLayer();
                        mMapView.addLayer(graphicsLayer);
    
                        SimpleMarkerSymbol simpleMarker = new SimpleMarkerSymbol(
                                Color.RED, 5, SimpleMarkerSymbol.STYLE.CIRCLE);
                        // GeometryEngine.project takes X (longitude) first
                        Point pointGeometry = GeometryEngine.project(
                                149.083404, -35.238019, mMapView.getSpatialReference());
                        Graphic pointGraphic = new Graphic(pointGeometry, simpleMarker);
                        graphicsLayer.addGraphic(pointGraphic);
                    }
                }
            });
        }
    
        @Override
        protected void onPause(){
            mMapView.pause();
            super.onPause();
        }
    
        @Override
        protected void onResume(){
            super.onResume();
            mMapView.unpause();
        }
    }