0

你好,

我是开发 ArcGIS 地图的新手。目前,我能够显示地图。但是如何使用经度和纬度创建默认位置并在我的代码中实现呢?

例如,我想设置这些坐标:(1.3002, 103.8641)。打开地图时,它会自动放大到这些坐标。

先感谢您。

这是我的代码:

public class HelloWorld extends Activity {
MapView mMapView = null;
ArcGISTiledMapServiceLayer tileLayer;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Retrieve the map and initial extent from XML layout
    mMapView = (MapView)findViewById(R.id.map);
    /* create a @ArcGISTiledMapServiceLayer */
    tileLayer = new ArcGISTiledMapServiceLayer(
            "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
    // Add tiled layer to MapView
    mMapView.addLayer(tileLayer);

}


@Override
protected void onPause() {
    super.onPause();
    mMapView.pause();
    }

@Override
protected void onResume() {
    super.onResume(); 
    mMapView.unpause();
}   

  }
4

1 回答 1

0

在向 中添加任何层之前MapView,设置其OnStatusChangedListener. 将代码添加到将经度/纬度坐标投影到地图坐标并将地图以地图坐标居中的监听器。

你可以这样做:

mMapView = (MapView)findViewById(R.id.map);

final double longitude = 103.8641;
final double latitude = 1.3002;
mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {

    @Override
    public void onStatusChanged(Object source, STATUS status) {
        if (STATUS.INITIALIZED.equals(status)) {
            Point mapPoint = GeometryEngine.project(longitude, latitude, mMapView.getSpatialReference());
            mMapView.centerAt(mapPoint, false);
        }
    }

});

/* create a @ArcGISTiledMapServiceLayer */
tileLayer = new ArcGISTiledMapServiceLayer(
        "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
// Add tiled layer to MapView
mMapView.addLayer(tileLayer);

如果您想同时居中并缩放到某个比例,您可以调用zoomToScale而不是centerAt.

于 2013-11-05T15:01:11.100 回答