||
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
文件名: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)
文件如下:
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2025-1-10 14:25
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社