【问题标题】:OSMDroid world map not showing upOSMDroid 世界地图未显示
【发布时间】:2019-06-03 09:44:42
【问题描述】:

我正在关注here 中的 OSMDroid 教程:

但我遇到了一些麻烦,我已经按照教程中的方式完成了所有操作,但是,当我运行应用程序时,它应该显示 世界地图,但我只看到网格和缩放按钮。

这是我的 Layout 和 MainActivity 代码:

布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    >

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <org.osmdroid.views.MapView android:id="@+id/map"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

    </LinearLayout>



    <org.osmdroid.views.MapView
        android:id="@+id/mapview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tilesource="Mapnik" />

</android.support.design.widget.CoordinatorLayout>

活动:

import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import org.osmdroid.api.IMapController;
import org.osmdroid.config.Configuration;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;


public class MainActivity extends AppCompatActivity{
    MapView map = null;


    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Context ctx = getApplicationContext();
        Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));

        map = (MapView) findViewById(R.id.map);
        map.setTileSource(TileSourceFactory.MAPNIK);
        map.setBuiltInZoomControls(true);
        map.setMultiTouchControls(true);
        IMapController mapController = map.getController();
        mapController.setZoom(9.5);
        GeoPoint startPoint = new GeoPoint(48.8583, 2.2944);
        mapController.setCenter(startPoint);
    }

    public void onResume(){
        super.onResume();
        map.onResume(); 
    }

    public void onPause(){
        super.onPause();
        map.onPause();  
    }
}

世界地图不应该在跑步时显示吗?

提前致谢!

【问题讨论】:

  • 您是否在您的 AndroidManifest.xml 中添加了所需的权限,即至少 INTERNETACCESS_NETWORK_STATE?如果这没有帮助,请检查您的日志消息。

标签: android openstreetmap osmdroid


【解决方案1】:

只需将您的 .xml 更改为以下 sn-p

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <org.osmdroid.views.MapView android:id="@+id/map"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

    </LinearLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多