无法在Android应用上显示osmdroid地图

时间:2016-12-06 11:16:45

标签: android android-emulator openstreetmap osmdroid

我试图将OpenStreetMap用于Android应用程序(API Level 24)。 我已经从MOBAC下载了地图以便在离线模式下使用它们,我将它们复制到/ mnt / sdcard / osmdroid中作为.zip文件

但是当我尝试在我的某个活动中显示地图时,我从控制台收到此错误:

I/OpenGLRenderer: Initialized EGL, version 1.4
E/EGL_emulation: tid 3023: eglSurfaceAttrib(1165): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f934e82c980, error=EGL_BAD_MATCH
I/OsmDroid: Using tile source: Mapnik
E/OsmDroid: unable to create a nomedia file. downloaded tiles may be visible to the gallery. open failed: ENOENT (No such file or directory)
E/SQLiteLog: (14) cannot open file at line 31278 of [2ef4f3a5b1]
E/SQLiteLog: (14) os_unix.c:31278: (2)open(/storage/emulated/0/osmdroid/tiles/cache.db) - 
E/SQLiteDatabase: Failed to open database     '/storage/emulated/0/osmdroid/tiles/cache.db'.
                  android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database 
                      at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
                      at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
                      at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:191)
                      at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
                      at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
                      at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
                      at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
                      at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
                      at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
                      at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:709)
                      at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:702)
                      at org.osmdroid.tileprovider.modules.SqlTileWriter.<init>(SqlTileWriter.java:44)
                      at org.osmdroid.tileprovider.MapTileProviderBasic.<init>(MapTileProviderBasic.java:76)
                      at org.osmdroid.tileprovider.MapTileProviderBasic.<init>(MapTileProviderBasic.java:50)
                      at org.osmdroid.views.MapView.<init>(MapView.java:170)
                      at org.osmdroid.views.MapView.<init>(MapView.java:200)
                      at java.lang.reflect.Constructor.newInstance(Native Method)
                      at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                      at com.example.miguel.urjctfgappmetromad.MainActivity.map(MainActivity.java:20)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                      at android.view.View.performClick(View.java:5198)
                      at android.view.View$PerformClick.run(View.java:21147)
                      at android.os.Handler.handleCallback(Handler.java:739)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/OsmDroid: Unable to start the sqlite tile writer. Check external storage availability.
            android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
                at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
                at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
                at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:191)
                at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
                at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
                at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
                at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
                at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
                at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
                at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:709)
                at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:702)
                at org.osmdroid.tileprovider.modules.SqlTileWriter.<init>(SqlTileWriter.java:44)
                at org.osmdroid.tileprovider.MapTileProviderBasic.<init>(MapTileProviderBasic.java:76)
                at org.osmdroid.tileprovider.MapTileProviderBasic.<init>(MapTileProviderBasic.java:50)
                at org.osmdroid.views.MapView.<init>(MapView.java:170)
                at org.osmdroid.views.MapView.<init>(MapView.java:200)
                at java.lang.reflect.Constructor.newInstance(Native Method)
                at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                at com.example.miguel.urjctfgappmetromad.MainActivity.map(MainActivity.java:20)
                at java.lang.reflect.Method.invoke(Native Method)
                at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                at android.view.View.performClick(View.java:5198)
                at android.view.View$PerformClick.run(View.java:21147)
                at android.os.Handler.handleCallback(Handler.java:739)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:148)
                at android.app.ActivityThread.main(ActivityThread.java:5417)
                at java.lang.reflect.Method.invoke(Native Method)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
I/OsmDroid: sdcard state: mounted
I/OsmDroid: sdcard state: mounted
E/SQLiteLog: (14) cannot open file at line 31278 of [2ef4f3a5b1]
E/SQLiteLog: (14) os_unix.c:31278: (2) open(/storage/emulated/0/osmdroid/tiles/cache.db) - 
E/SQLiteDatabase: Failed to open database '/storage/emulated/0/osmdroid/tiles/cache.db'.
                  android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
                      at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
                      at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
                      at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:191)
                      at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
                      at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
                      at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
                      at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
                      at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
                      at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
                      at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:709)
                      at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:702)
                      at org.osmdroid.tileprovider.modules.SqlTileWriter.<init>(SqlTileWriter.java:44)
                      at org.osmdroid.tileprovider.modules.MapTileSqlCacheProvider.<init>(MapTileSqlCacheProvider.java:57)
                      at org.osmdroid.tileprovider.modules.MapTileSqlCacheProvider.<init>(MapTileSqlCacheProvider.java:63)
                      at org.osmdroid.tileprovider.MapTileProviderBasic.<init>(MapTileProviderBasic.java:88)
                      at org.osmdroid.tileprovider.MapTileProviderBasic.<init>(MapTileProviderBasic.java:50)
                      at org.osmdroid.views.MapView.<init>(MapView.java:170)
                      at org.osmdroid.views.MapView.<init>(MapView.java:200)
                      at java.lang.reflect.Constructor.newInstance(Native Method)
                      at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
                      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                      at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                      at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                      at com.example.miguel.urjctfgappmetromad.MainActivity.map(MainActivity.java:20)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                      at android.view.View.performClick(View.java:5198)
                      at android.view.View$PerformClick.run(View.java:21147)
                      at android.os.Handler.handleCallback(Handler.java:739)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/OsmDroid: Unable to start the sqlite tile writer. Check external storage availability.
            android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
                at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
                at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
                at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:191)
                at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
                at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
                at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
                at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
                at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
                at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
                at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:709)
                at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:702)
                at org.osmdroid.tileprovider.modules.SqlTileWriter.<init>(SqlTileWriter.java:44)
                at org.osmdroid.tileprovider.modules.MapTileSqlCacheProvider.<init>(MapTileSqlCacheProvider.java:57)
                at org.osmdroid.tileprovider.modules.MapTileSqlCacheProvider.<init>(MapTileSqlCacheProvider.java:63)
                at org.osmdroid.tileprovider.MapTileProviderBasic.<init>(MapTileProviderBasic.java:88)
                at org.osmdroid.tileprovider.MapTileProviderBasic.<init>(MapTileProviderBasic.java:50)
                at org.osmdroid.views.MapView.<init>(MapView.java:170)
                at org.osmdroid.views.MapView.<init>(MapView.java:200)
                at java.lang.reflect.Constructor.newInstance(Native Method)
                at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                at com.example.miguel.urjctfgappmetromad.MainActivity.map(MainActivity.java:20)
                at java.lang.reflect.Method.invoke(Native Method)
                at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
                at android.view.View.performClick(View.java:5198)
                at android.view.View$PerformClick.run(View.java:21147)
                at android.os.Handler.handleCallback(Handler.java:739)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:148)
                at android.app.ActivityThread.main(ActivityThread.java:5417)
                at java.lang.reflect.Method.invoke(Native Method)
                at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    I/OsmDroid: sdcard state: mounted
    I/OsmDroid: Tile cache increased from 9 to 48
    D/OsmDroid: Unable to store cached tile from Mapnik /0/0/0, database not available.'

这就是我的activity_map.xml的样子:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;

public class MapActivity extends AppCompatActivity {
    private MapView myOpenMapView;
    private MapController myMapController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        myOpenMapView = (MapView)findViewById(R.id.map);
        myOpenMapView.setBuiltInZoomControls(true);
        myOpenMapView.setTileSource(TileSourceFactory.HIKEBIKEMAP);
        myMapController = (MapController) myOpenMapView.getController();
        myMapController.setZoom(12);
        myOpenMapView.setMultiTouchControls(true);
    }
}

这是我的activity_map.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    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>

这就是我修改AndroidManifest.xml的方式:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.miguel.urjctfgappmetromad">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".DisplayMessageActivity" />
        <activity android:name=".MapActivity"></activity>
    </application>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>

有人知道如何解决它吗?谢谢!!!

0 个答案:

没有答案