依赖
implementation 'com.github.getActivity:XXPermissions:20.0'
implementation 'com.amap.api:navi-3dmap-location-search:10.0.800_3dmap10.0.800_loc6.4.5_sea9.7.2'
CoreUtil封装一些方法
- ref link: https://gitee.com/EEPPEE_admin/amap-android-sdk-memo
显示地图
- https://lbs.amap.com/api/android-sdk/guide/create-map/show-map
private val mMapView: MapView by lazy { findViewById(R.id.map) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
CoreUtil.initPermission(this)
CoreUtil.initGaodeAllPrivacyFirst(this, true, true, true)
mMapView.onCreate(savedInstanceState)
if (mAmap == null) {
mAmap = mMapView.map
}
}
显示定位蓝点
- https://lbs.amap.com/api/android-sdk/guide/create-map/mylocation
- 在显示地图的基础下面再添加
val myLocationStyle: MyLocationStyle = MyLocationStyle()
myLocationStyle.interval(2000)
mAmap?.myLocationStyle = myLocationStyle
mAmap?.isMyLocationEnabled = true
显示3d地形图
- https://lbs.amap.com/api/android-sdk/guide/create-map/terrain
#注意在MapView初始化前调用
MapsInitializer.setTerrainEnable(true)
显示室内地图
- https://lbs.amap.com/api/android-sdk/guide/create-map/indoor
amapinstance.showIndoorMap(true)
设置地图图层
- https://lbs.amap.com/api/android-sdk/guide/create-map/set-maptype
amapinstance.mapType = AMap.MAP_TYPE_NIGHT
离线地图
- https://lbs.amap.com/api/android-sdk/guide/create-map/offline-map
startActivity(Intent(this, com.amap.api.maps.offlinemap.OfflineMapActivity::class.java))
显示英文
- https://lbs.amap.com/api/android-sdk/guide/create-map/english-map
amapinstance.apply {
isTrafficEnabled = true
setMapLanguage("en")
}
添加marker
- https://lbs.amap.com/api/android-sdk/guide/draw-on-map/draw-marker
fun addMarkerOnAMap(aMap: AMap) {
val latLng = LatLng(39.906901, 116.397972)
val marker = aMap.addMarker(
MarkerOptions()
.position(latLng)
.title("北京")
.snippet("地道滴滴滴大豆")
.setFlat(true)
)
val anim = RotateAnimation(marker.rotateAngle, marker.rotateAngle + 180)
val duration = 1000L
with(marker) {
anim.setDuration(duration)
anim.setInterpolator(LinearInterpolator())
setAnimation(anim)
startAnimation()
}
}
绘制线
- https://lbs.amap.com/api/android-sdk/guide/draw-on-map/draw-polyline
fun drawLineOnAMap(aMap: AMap) {
val latLngs = listOf(
LatLng(39.999391, 116.135972),
LatLng(39.898323, 116.057694),
LatLng(39.900430, 116.265061),
LatLng(39.955192, 116.140092)
)
val polyline = aMap.addPolyline(
PolylineOptions()
.addAll(latLngs)
.width(25f)
.color(Color.argb(255, 1, 1, 1))
)
}
题外话
- 一般添加jitpack.io(只要链接不死)
- 建议添加android.enableJetifier=true