【问题标题】:Osmdroid maps not loading on my deviceOsmdroid 地图未在我的设备上加载
【发布时间】:2016-10-18 05:18:32
【问题描述】:

我有一个 Alcatel One Touch 7040,当我在其上测试我的 osmdroid 样本时,地图不呈现。我已经在其他设备上进行了测试,地图在其中正确渲染,只有在这个设备上它们不是。我认为我的设备内存不足,所以我从设备中删除了一些应用程序,但仍然没有任何改善,谁能告诉我可能是什么原因?

以下是我的logcat(由于超出字数限制,部分内容已被删除):

10-17 23:03:27.688 26424-26424/marine.com.osmsample I/OsmDroid: Using tile source: Mapnik
10-17 23:03:27.702 26424-26424/marine.com.osmsample E/OsmDroid: unable to create a nomedia file. downloaded tiles may be visible to the gallery. open failed: ENOENT (No such file or directory)
10-17 23:03:27.715 26424-26424/marine.com.osmsample E/SQLiteLog: (14) cannot open file at line 30202 of [00bb9c9ce4]
10-17 23:03:27.715 26424-26424/marine.com.osmsample E/SQLiteLog: (14) os_unix.c:30202: (2) open(/storage/sdcard0/osmdroid/tiles/cache.db) - 
10-17 23:03:27.729 26424-26424/marine.com.osmsample E/SQLiteDatabase: Failed to open database '/storage/sdcard0/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:209)
                                                                          at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
                                                                          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:804)
                                                                          at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
                                                                          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.constructNative(Native Method)
                                                                          at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                                                                          at android.view.LayoutInflater.createView(LayoutInflater.java:587)
                                                                          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
                                                                          at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                                          at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:285)
                                                                          at android.app.Activity.setContentView(Activity.java:1882)
                                                                          at marine.com.osmsample.MainActivity.onCreate(MainActivity.java:55)
                                                                          at android.app.Activity.performCreate(Activity.java:5121)
                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2446)
                                                                          at android.app.ActivityThread.access$600(ActivityThread.java:165)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:107)
                                                                          at android.os.Looper.loop(Looper.java:194)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5434)
                                                                          at java.lang.reflect.Method.invokeNative(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:525)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                          at dalvik.system.NativeStart.main(Native Method)
10-17 23:03:27.731 26424-26424/marine.com.osmsample 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:209)
                                                                    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
                                                                    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:804)
                                                                    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
                                                                    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.constructNative(Native Method)
                                                                    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                                                                    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
                                                                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
                                                                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                                    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:285)
                                                                    at android.app.Activity.setContentView(Activity.java:1882)
                                                                    at marine.com.osmsample.MainActivity.onCreate(MainActivity.java:55)
                                                                    at android.app.Activity.performCreate(Activity.java:5121)
                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2446)
                                                                    at android.app.ActivityThread.access$600(ActivityThread.java:165)
                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:107)
                                                                    at android.os.Looper.loop(Looper.java:194)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5434)
                                                                    at java.lang.reflect.Method.invokeNative(Native Method)
                                                                    at java.lang.reflect.Method.invoke(Method.java:525)
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                    at dalvik.system.NativeStart.main(Native Method)
10-17 23:03:27.732 26424-26424/marine.com.osmsample D/dalvikvm: create interp thread : stack size=128KB
10-17 23:03:27.732 26424-26424/marine.com.osmsample D/dalvikvm: create new thread
10-17 23:03:27.732 26424-26424/marine.com.osmsample D/dalvikvm: new thread created
10-17 23:03:27.732 26424-26424/marine.com.osmsample D/dalvikvm: update thread list
10-17 23:03:27.732 26424-26944/marine.com.osmsample D/dalvikvm: threadid=17: interp stack at 0x5f42b000
10-17 23:03:27.732 26424-26944/marine.com.osmsample D/dalvikvm: threadid=17: created from interp
10-17 23:03:27.732 26424-26424/marine.com.osmsample D/dalvikvm: start new thread
10-17 23:03:27.733 26424-26944/marine.com.osmsample D/dalvikvm: threadid=17: notify debugger
10-17 23:03:27.733 26424-26944/marine.com.osmsample D/dalvikvm: threadid=17 (Thread-2646): calling run()
10-17 23:03:27.733 26424-26944/marine.com.osmsample D/dalvikvm: threadid=17: exiting
10-17 23:03:27.733 26424-26944/marine.com.osmsample D/dalvikvm: threadid=17: bye!
10-17 23:03:27.739 26424-26424/marine.com.osmsample I/OsmDroid: sdcard state: mounted
10-17 23:03:27.745 26424-26424/marine.com.osmsample I/OsmDroid: sdcard state: mounted
10-17 23:03:27.746 26424-26424/marine.com.osmsample E/SQLiteLog: (14) cannot open file at line 30202 of [00bb9c9ce4]
10-17 23:03:27.746 26424-26424/marine.com.osmsample E/SQLiteLog: (14) os_unix.c:30202: (2) open(/storage/sdcard0/osmdroid/tiles/cache.db) - 
10-17 23:03:27.749 26424-26424/marine.com.osmsample E/SQLiteDatabase: Failed to open database '/storage/sdcard0/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:209)
                                                                          at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
                                                                          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:804)
                                                                          at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
                                                                          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.constructNative(Native Method)
                                                                          at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                                                                          at android.view.LayoutInflater.createView(LayoutInflater.java:587)
                                                                          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
                                                                          at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                                          at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:285)
                                                                          at android.app.Activity.setContentView(Activity.java:1882)
                                                                          at marine.com.osmsample.MainActivity.onCreate(MainActivity.java:55)
                                                                          at android.app.Activity.performCreate(Activity.java:5121)
                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2446)
                                                                          at android.app.ActivityThread.access$600(ActivityThread.java:165)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:107)
                                                                          at android.os.Looper.loop(Looper.java:194)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5434)
                                                                          at java.lang.reflect.Method.invokeNative(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:525)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                          at dalvik.system.NativeStart.main(Native Method)
10-17 23:03:27.753 26424-26424/marine.com.osmsample 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:209)
                                                                    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
                                                                    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:804)
                                                                    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
                                                                    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.constructNative(Native Method)
                                                                    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
                                                                    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
                                                                    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
                                                                    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                                    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                                    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:285)
                                                                    at android.app.Activity.setContentView(Activity.java:1882)
                                                                    at marine.com.osmsample.MainActivity.onCreate(MainActivity.java:55)
                                                                    at android.app.Activity.performCreate(Activity.java:5121)
                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1146)
                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2446)
                                                                    at android.app.ActivityThread.access$600(ActivityThread.java:165)
                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:107)
                                                                    at android.os.Looper.loop(Looper.java:194)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5434)
                                                                    at java.lang.reflect.Method.invokeNative(Native Method)
                                                                    at java.lang.reflect.Method.invoke(Method.java:525)
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                    at dalvik.system.NativeStart.main(Native Method)  
10-17 23:03:39.774 26424-27015/marine.com.osmsample D/OsmDroid: Unable to store cached tile from Mapnik /14/9291/6359, database not available.
10-17 23:03:39.792 26424-27015/marine.com.osmsample I/System.out: [CDS]rx timeout:0
10-17 23:03:39.819 26424-27003/marine.com.osmsample D/OsmDroid: Unable to store cached tile from Mapnik /14/9292/6359, database not available.
10-17 23:03:39.823 26424-27003/marine.com.osmsample I/System.out: [CDS]rx timeout:0
10-17 23:03:39.846 26424-27015/marine.com.osmsample D/OsmDroid: Unable to store cached tile from Mapnik /14/9290/6359, database not available.
10-17 23:03:39.852 26424-27015/marine.com.osmsample I/System.out: [CDS]rx timeout:0

【问题讨论】:

  • 仅根据错误日志,我会说您的 microSD 卡空间不足 - 甚至可能在安装过​​程中。清除 microSD 卡上的空间,然后删除并安装您的应用程序。也可以尝试使用不同的 microSD 卡。

标签: android openstreetmap osmdroid


【解决方案1】:

设备的 API 级别是什么?这可能是权限问题。有时android也会将Environment.getExternalStorageDir()挂载为只读,这是错误的。有一天,我将通过变通方法解决此问题。

osmdroid 提供的示例应用程序可以工作吗?您不仅必须启动它,还必须放大一点。示例应用附带了一些缓存切片。

查看堆栈跟踪,Environment.getExternalStorageDir() 正在返回一个只读挂载点。因此,唯一合理的解决方案是告诉 osmdroid 在该类型的设备上为缓存使用不同的位置。它可以轻松完成,但必须在创建地图视图之前完成。此链接包含使用 osmdroid 进行的 API 调用

Using osmdroid without getting access to external storage

这个答案https://stackoverflow.com/a/15612964/1203182 有一些很棒的代码可以返回可写的挂载点/路径列表。提示用户询问存储缓存的位置可能是个好主意

编辑:在 osmdroid 5.6 中添加,添加了我讨论的解决方法,以及示例应用程序“打开地图”中的示例,向您展示如何使用它。 osmdroid 5.6 及更高版本的默认缓存位置是最大的可写存储分区。然后将其保存为首选项(再次查看示例应用)

【讨论】:

  • 我们从 Play 商店下载的示例应用程序运行良好,但是当我按照教程制作自己的应用程序时,它却不行。设备为 api 19(Android 4.4)
  • 你能看看我发布的关于指南针的另一个query,我需要帮助,谢谢!
  • 我刚刚更新了 osmdroid 以包含类似的功能以及如何控制它的示例
  • 我已经尝试了你合并到osmdriod github的解决方案,仍然地图没有显示在alcatel上,这是在github上添加新的代码表单解决方案后创建的文件夹的截图screenshot1,@987654325 @, screenshot3
  • 该应用是否有互联网连接?是授予权限的 api23 吗?
【解决方案2】:

如果您已经请求许可但仍然无法显示地图,我可以通过以下方式修复它,来自 answer

val osmConfig = Configuration.getInstance()
osmConfig.userAgentValue = packageName
val basePath = File(cacheDir.absolutePath, "osmdroid")
osmConfig.osmdroidBasePath = basePath
val tileCache  = File(osmConfig.osmdroidBasePath, "tile")
osmConfig.osmdroidTileCache = tileCache

【讨论】:

    【解决方案3】:

    伙计们 android 6 给出了分配外部存储权限的新方法,所以我给出了:

    ActivityCompat.requestPermissions(LoginActivity.this,
     new String[{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION}, 1);
    

    否则转到

    settings-&gt;Applications-&gt;Application Manager-&gt;choose your app-&gt;permission

    以及权限,以便问题得到解决。

    【讨论】:

      【解决方案4】:

      对于科特林

      ActivityCompat.requestPermissions(this,
       arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION), 1)
      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-19
        • 2021-10-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多