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

发布于 2024-12-23 18:46:48 字数 534 浏览 0 评论 0原文

我正在开发一个 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"));}

我不知道如何在模拟器上加载地图时首次加载地图时设置缩放级别,地图太小了。

有人能帮我解决这个问题吗?

任何帮助将不胜感激。

I'm developing a OneMap Android application and the code is as follows:

    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"));}

I'm lost at figuring out how to set the zoom level when the map is first loaded on the emulator as on load, the map is too small.

Could anyone help me with this?

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倦话 2024-12-30 18:46:48
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;
    }
    }
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;
    }
    }
夜吻♂芭芘 2024-12-30 18:46:48

首先你需要知道你当前的位置,现在你可以使用新的位置 API,这里是

LatLng latlng = new LatLng(location.getLatitude(),location.getLongitude());         
map.moveCamera(CameraUpdateFactory.newLatLng(latlng));
map.animateCamera(CameraUpdateFactory.zoomTo(2.0f));

但请记住 .connect() LocationClient 在 onCreate() 下。

如果您不遵循,您将收到以下错误消息
Android:位于 com.google.android.gms.internal .uy(来源不明)

Firstly you need to know your current location, now you can use new location api, here is the guide.
then you can add below command under Onconnect()

LatLng latlng = new LatLng(location.getLatitude(),location.getLongitude());         
map.moveCamera(CameraUpdateFactory.newLatLng(latlng));
map.animateCamera(CameraUpdateFactory.zoomTo(2.0f));

but remember .connect() LocationClient under onCreate().

here is the error message you will get if you not follow
Android: at com.google.android.gms.internal.u.y(Unknown Source)

雨轻弹 2024-12-30 18:46:48

您似乎正在使用 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);

让我知道它是否适合您。

It looks like you`re using ArcGIS maps.
Please use the below sample code to set zoom level on the launch of the maps.

<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" />

you can also set in activity file,

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

Let me know if it works for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文