依賴
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