自定义用户位置图标
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package com.abbidot.tracker.ui.fragment.map.googlemap
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Point
|
||||
import android.location.Location
|
||||
@@ -11,7 +9,6 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.abbidot.baselibrary.constant.MMKVKey
|
||||
@@ -93,6 +90,9 @@ abstract class BaseGoogleMapFragment :
|
||||
//自定显示宠物头像地点信息图层
|
||||
var mMarker: Marker? = null
|
||||
|
||||
//自定显示用户地点信息图层
|
||||
var mUserMarker: Marker? = null
|
||||
|
||||
//宠物大头针设置自定义头像
|
||||
private var mPetHeadIconBitmap: Bitmap? = null
|
||||
|
||||
@@ -300,18 +300,15 @@ abstract class BaseGoogleMapFragment :
|
||||
* 切换用户和宠物的位置居中显示,移动摄像头中心
|
||||
*/
|
||||
fun switchShowLocation(@ConstantInt type: Int) {
|
||||
if (type == ConstantInt.PetLocationType) {
|
||||
val latLng = if (type == ConstantInt.PetLocationType) {
|
||||
//刷新下用户当前的位置
|
||||
getLastLocation()
|
||||
mPetLatLng?.let {
|
||||
moveCameraLocation(it)
|
||||
}
|
||||
mPetLatLng
|
||||
} else {
|
||||
mGoogleMap?.apply {
|
||||
mUserLatLng?.let {
|
||||
moveCamera(CameraUpdateFactory.newLatLngZoom(it, mGoogleMapZoom))
|
||||
}
|
||||
}
|
||||
mUserLatLng
|
||||
}
|
||||
latLng?.let {
|
||||
moveCameraLocation(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,6 +369,21 @@ abstract class BaseGoogleMapFragment :
|
||||
mGoogleMap?.apply {
|
||||
mMarker = addMarker(markerOptions)
|
||||
}
|
||||
setUserMarker()
|
||||
}
|
||||
|
||||
fun setUserMarker() {
|
||||
mUserLatLng?.let {
|
||||
if (null == mUserMarker) {
|
||||
mUserMarker = addImageMarker(it, R.drawable.pic_avatar_df)
|
||||
} else {
|
||||
if (it.latitude == mUserMarker!!.position.latitude && it.longitude == mUserMarker!!.position.longitude) {
|
||||
} else {
|
||||
mUserMarker?.remove()
|
||||
mUserMarker = addImageMarker(it, R.drawable.pic_avatar_df)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -902,15 +914,15 @@ abstract class BaseGoogleMapFragment :
|
||||
//显示实时交通信息
|
||||
// isTrafficEnabled = true
|
||||
//检测权限,开启用户的当前位置https://developers.google.cn/maps/documentation/android-sdk/location?hl=zh-cn
|
||||
if (ActivityCompat.checkSelfPermission(
|
||||
mContext!!, Manifest.permission.ACCESS_FINE_LOCATION
|
||||
) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
|
||||
mContext!!, Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
//启用“我的位置”图层。
|
||||
isMyLocationEnabled = true
|
||||
}
|
||||
// if (ActivityCompat.checkSelfPermission(
|
||||
// mContext!!, Manifest.permission.ACCESS_FINE_LOCATION
|
||||
// ) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
|
||||
// mContext!!, Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
// ) == PackageManager.PERMISSION_GRANTED
|
||||
// ) {
|
||||
// //启用“我的位置”图层。
|
||||
// isMyLocationEnabled = true
|
||||
// }
|
||||
uiSettings.let {
|
||||
//禁止显示“我的位置”按钮。
|
||||
it.isMyLocationButtonEnabled = false
|
||||
@@ -952,7 +964,10 @@ abstract class BaseGoogleMapFragment :
|
||||
}
|
||||
if (null != location) {
|
||||
mUserLatLng = LatLng(location.latitude, location.longitude)
|
||||
if (isLocationSuccessCallback) locationSuccess(location)
|
||||
if (isLocationSuccessCallback) {
|
||||
setUserMarker()
|
||||
locationSuccess(location)
|
||||
}
|
||||
isLocationSuccessCallback = false
|
||||
} else requestCurrentLocation()
|
||||
}
|
||||
|
||||
@@ -297,6 +297,7 @@ class HistoryDataGoogleMapFragment : BaseGoogleMapFragment() {
|
||||
mMarker = addMarker(mMarkerOptions)
|
||||
//显示最上面,层级最高
|
||||
mMarker?.zIndex = 1f
|
||||
setUserMarker()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user