我一直试图让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);
答案 0 :(得分:0)
两个问题:
Point
时,首先指定X(经度),然后指定Y(纬度)。 149.083404不是有效的纬度,所以我认为你的意思是经度。切换它们。GeometryEngine.project
将你的点投射到地图的空间参考,除非你打电话给方法的参数为longitude
和latitude
,而不是x
和y
。我无法判断您是使用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();
}
}