chaoshu的个人博客分享 http://blog.sciencenet.cn/u/chaoshu

博文

osmdroid在android 9以上的设备不显示在线瓦片地图的解决方法

已有 4483 次阅读 2019-12-27 11:26 |个人分类:osmdroid|系统分类:科研笔记

osmdroid:OpenStreetMap-Tools for Android http://osmdroid.github.io/osmdroid/

1)在线地图加载,需要申请读写权限、网络访问权限,这些都是属于危险权限,必须进行动态申请;

解决:推荐使用第三方库xxpermissios

https://github.com/getActivity/XXPermissions

//权限请求框架
implementation 'com.hjq:xxpermissions:6.0'

2)osmdroid在Android 9以后的设备上存在debug,申请http请求错误;

解决:首先,升级最新版本的SDK;

//OpenStreetMap-Tools for Android
implementation 'org.osmdroid:osmdroid-android:6.1.5'
implementation 'org.osmdroid:osmdroid-shape:6.1.5'
implementation 'com.github.MKergall:osmbonuspack:6.6.0'


其次,按照下面步骤操作:

1、在res/新建一个xml/目录,然后新建App Action XML file

image.png

文件名:network_security_config.xml;复制下面内容到文件中

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">dev.virtualearth.net</domain>
    </domain-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">tiles.wmflabs.org</domain>
    </domain-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">tile.cloudmade.com</domain>
    </domain-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">openptmap.org</domain>
    </domain-config>
</network-security-config>

2、在src/main/AndroidManifest.xml中设置如下

<application
   android:name=".MyApp"
   android:allowBackup="false"
   android:configChanges="screenSize|keyboardHidden|orientation|keyboard"
   android:icon="@mipmap/ic_launcher"
   android:label="@string/app_name"
   android:roundIcon="@mipmap/ic_launcher_round"
   android:supportsRtl="true"
   android:networkSecurityConfig="@xml/network_security_config"
   android:largeHeap="true"
   android:theme="@style/AppTheme"
   android:windowSoftInputMode="adjustPan|stateHidden">

     ......

</application>

在<application>中添加

android:networkSecurityConfig="@xml/network_security_config"
android:largeHeap="true"


3、添加谷歌地图、高德地图等在线瓦片,注意一定要要是https,不能是http。(http-->https)

文件如下:

MapTileSource.java




https://blog.sciencenet.cn/blog-858128-1211684.html

上一篇:Android使用GreenDao时,新增表(图层)的时候出现 no such table的异常
下一篇:Andriod中使用assets读取文件
收藏 IP: 119.79.228.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (2 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-25 19:57

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部