如何在onCreate()中设置MapView的缩放级别?

4
我正在开发一个OneMap的Android应用程序,代码如下:
    private MapView map;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

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

        map.addLayer(new ArcGISTiledMapServiceLayer(Practice_3.this,
                "http://www.onemap.sg/ArcGIS/rest/services/BASEMAP/MapServer"));}

我在弄清楚如何在模拟器上加载地图时设置缩放级别方面感到困惑,因为加载时地图太小了。

有人能帮帮我吗?

非常感谢任何帮助。


有很多关于在Android上使用Google Maps应用程序的教程可以在线获取。看起来你没有查阅它们。不要在基础问题上使用stackoverflow,这并不好。 - Yugandhar Babu
@Yugandhar Babu,你说得对,但这些话看起来不太友好。 - atom2ueki
3个回答

0

看起来您正在使用ArcGIS地图。 请使用以下示例代码在地图启动时设置缩放级别。

<com.esri.android.map.MapView
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    mapoptions.MapType="Topo"
    mapoptions.ZoomLevel="13"
    mapoptions.center="33.666354, -117.903557" />

你也可以在活动文件中进行设置,

 MapOptions options = new MapOptions(MapType.TOPO, 23, -110, 9);

如果这对你有用,请告诉我。


0
public class MyMap_MapControllerActivity extends MapActivity {

    private MapView mapView;
    //private MapController mapController;
     MapView.LayoutParams lp;
     int y = 10;
        int x = 10;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mapView = (MapView)findViewById(R.id.map_view);
        mapView.setSatellite(true);
        mapView.setStreetView(true);
        mapView.setTraffic(true);



    GeoPoint center = mapView.getMapCenter();
    int latSpan = mapView.getLatitudeSpan();
    int longSpan = mapView.getLongitudeSpan();




    lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
    MapView.LayoutParams.WRAP_CONTENT,
    x, y,
    MapView.LayoutParams.TOP_LEFT);
    View zoomControls = mapView.getZoomControls();
    mapView.addView(zoomControls, lp);
    mapView.displayZoomControls(true);
    }



    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
    }

0
首先,您需要知道您当前的位置,现在您可以使用新的位置API,这里是指南。 然后,在Onconnect()下面添加以下命令。
LatLng latlng = new LatLng(location.getLatitude(),location.getLongitude());         
map.moveCamera(CameraUpdateFactory.newLatLng(latlng));
map.animateCamera(CameraUpdateFactory.zoomTo(2.0f));

但是请记住,在 onCreate() 中调用 .connect() LocationClient

如果不遵循此步骤,您将会收到以下错误信息: Android: at com.google.android.gms.internal.u.y(Unknown Source)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接