关于
前几天公司要求调研一下here map地图是否支持等值路由等线图这个功能,然后就去google了一下。因为不是国内的地图,然后在最后下载Android对应的sdk(探索版explore)需要有对应支付的功能,即使不收费,所以也需要有类似PayPal等支付账号。本篇文章即提供最新版的explore 版Android sdk(导入项目的是aar文件)
目前最新版基于时间 2022-5-29
sdk的下载链接我会放到文章末尾,以百度网盘形式。
配置
继续不需要下载,如果你想真正使用到项目而不是仅限于测试的话也需要注册账号然后填写一系列信息,然后创建一个项目如下:
然后会有提示你下载一个文件,文件里面包括对应的项目的id和secret,打开如下图:
然后我们将它写到我们项目的Androidmanifest.xml里面:
<meta-data
android:name="com.here.sdk.access_key_id"
android:value="JqOFpFBmTqMAMn_s49QIVw" />
<meta-data
android:name="com.here.sdk.access_key_secret"
android:value="zHujQuPPQVVxb2aMrUfW-1iXkmVGBUKQ3FBR4Y3Qq7h67RA0zH8Q_PlQ-jO15ph485qlM3ITDJhFfVbDZX2hNw" />
还有就是对应的here map的aar文件导入以及build文件的修改如下:
项目build文件:
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'], exclude : ['*mock*.jar'])
重新sync一下build,然后我们就可以使用here map地图了
简单使用
here map 的几乎所有功能都是基于mapScene,简单实现地图展示。
首先添加地图控件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".HereMapActivity">
<com.here.sdk.mapview.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.here.sdk.mapview.MapView>
</androidx.constraintlayout.widget.ConstraintLayout>
然后在代码里面使用:
private var mapView: MapView? = null
private val locationRequest = registerForActivityResult(ActivityResultContracts.RequestPermission()){
if(it){
loadMapScene()
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setCo