Commit 4a2e9f27 authored by wanglei's avatar wanglei

...

parent bd2488f7
...@@ -61,6 +61,8 @@ dependencies { ...@@ -61,6 +61,8 @@ dependencies {
//google地图 //google地图
implementation(libs.play.services.maps) implementation(libs.play.services.maps)
//google位置服务
implementation("com.google.android.gms:play-services-location:21.0.1")
//广告 //广告
......
...@@ -12,5 +12,6 @@ data class ViewingBean( ...@@ -12,5 +12,6 @@ data class ViewingBean(
data class LocationDate( data class LocationDate(
val longitude: Double, val longitude: Double,
val latitude: Double, val latitude: Double,
val power: Double, val power: Int,
val timezone: Long,
) )
\ No newline at end of file
...@@ -40,6 +40,7 @@ object LocationPositionUtils { ...@@ -40,6 +40,7 @@ object LocationPositionUtils {
data.put("latitude", latLng.latitude) data.put("latitude", latLng.latitude)
data.put("longitude", latLng.longitude) data.put("longitude", latLng.longitude)
data.put("power", power) data.put("power", power)
data.put("timezone", System.currentTimeMillis())
LogEx.logDebug(TAG, "latitude=${latLng.latitude} longitude=${latLng.longitude} power=$power") LogEx.logDebug(TAG, "latitude=${latLng.latitude} longitude=${latLng.longitude} power=$power")
val bp = JSONObject() val bp = JSONObject()
// .put("${pkg}_1", "") // .put("${pkg}_1", "")
......
...@@ -2,7 +2,6 @@ package com.base.locationsharewhite.map ...@@ -2,7 +2,6 @@ package com.base.locationsharewhite.map
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.Color
import android.location.Criteria import android.location.Criteria
import android.location.Location import android.location.Location
import android.location.LocationManager import android.location.LocationManager
...@@ -14,30 +13,36 @@ import com.google.android.gms.maps.model.LatLng ...@@ -14,30 +13,36 @@ import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.LatLngBounds import com.google.android.gms.maps.model.LatLngBounds
import com.google.android.gms.maps.model.Marker import com.google.android.gms.maps.model.Marker
import com.google.android.gms.maps.model.MarkerOptions import com.google.android.gms.maps.model.MarkerOptions
import com.google.android.gms.maps.model.PolylineOptions
import kotlin.math.abs
object MapUtils { object MapUtils {
private val TAG = "MapUtils"
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
fun Context.getLastKnowLatLng(): LatLng { fun Context.getLatLngByLocationManager(): LatLng? {
var latitude: Double = -1.0
var longitude: Double = -1.0
val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager? val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager?
if (locationManager != null) { if (locationManager != null) {
val provider: String? = locationManager.getBestProvider(Criteria(), true) val provider: String? = locationManager.getBestProvider(Criteria(), true)
if (provider != null) { if (provider != null) {
val lastKnownLocation: Location? = locationManager.getLastKnownLocation(provider) val lastKnownLocation: Location? = locationManager.getLastKnownLocation(provider)
val latitude: Double = lastKnownLocation?.latitude ?: 0.0//维度 latitude = lastKnownLocation?.latitude ?: -1.0//维度
val longitude: Double = lastKnownLocation?.longitude ?: 0.0//经度 longitude = lastKnownLocation?.longitude ?: -1.0//经度
return LatLng(latitude, longitude)
} }
} }
return if (latitude == -1.0 || longitude == -1.0) {
null
} else {
LatLng(latitude, longitude)
}
return LatLng(0.0, 0.0)
} }
/** /**
* 添加view为Marker * 添加view为Marker
*/ */
...@@ -55,6 +60,9 @@ object MapUtils { ...@@ -55,6 +60,9 @@ object MapUtils {
) )
} }
/**
* 多个经纬度相机移动合适位置
*/
fun GoogleMap.cameraMovePointsBounds(point1: LatLng, point2: LatLng, padding: Int) { fun GoogleMap.cameraMovePointsBounds(point1: LatLng, point2: LatLng, padding: Int) {
// 创建包含两个点的边界 // 创建包含两个点的边界
val bounds = LatLngBounds.Builder().include(point1).include(point2).build() val bounds = LatLngBounds.Builder().include(point1).include(point2).build()
......
...@@ -2,11 +2,13 @@ package com.base.locationsharewhite.ui.locationmap ...@@ -2,11 +2,13 @@ package com.base.locationsharewhite.ui.locationmap
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.graphics.Color import android.graphics.Color
import android.os.Build
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.animation.LinearInterpolator import android.view.animation.LinearInterpolator
import androidx.activity.addCallback import androidx.activity.addCallback
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.locationsharewhite.BuildConfig
import com.base.locationsharewhite.R import com.base.locationsharewhite.R
import com.base.locationsharewhite.bean.ConstObject import com.base.locationsharewhite.bean.ConstObject
import com.base.locationsharewhite.bean.ViewingBean import com.base.locationsharewhite.bean.ViewingBean
...@@ -15,26 +17,22 @@ import com.base.locationsharewhite.helper.BaseActivity ...@@ -15,26 +17,22 @@ import com.base.locationsharewhite.helper.BaseActivity
import com.base.locationsharewhite.helper.MyApplication import com.base.locationsharewhite.helper.MyApplication
import com.base.locationsharewhite.location.LocationShareListUtils import com.base.locationsharewhite.location.LocationShareListUtils
import com.base.locationsharewhite.map.MapUtils.addLocationMarker import com.base.locationsharewhite.map.MapUtils.addLocationMarker
import com.base.locationsharewhite.map.MapUtils.cameraMovePointsBounds import com.base.locationsharewhite.map.MapUtils.getLatLngByLocationManager
import com.base.locationsharewhite.map.MapUtils.getLastKnowLatLng
import com.base.locationsharewhite.ui.main.ViewerAdapter
import com.base.locationsharewhite.ui.views.DialogView.showMapTypeDialog import com.base.locationsharewhite.ui.views.DialogView.showMapTypeDialog
import com.base.locationsharewhite.utils.BarUtils import com.base.locationsharewhite.utils.BarUtils
import com.base.locationsharewhite.utils.BitmapUtils
import com.base.locationsharewhite.utils.LogEx import com.base.locationsharewhite.utils.LogEx
import com.base.locationsharewhite.utils.PermissionUtils.checkLocationPermission import com.base.locationsharewhite.utils.PermissionUtils.checkLocationPermission
import com.base.locationsharewhite.utils.ToastUtils.toast
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.gms.maps.CameraUpdateFactory import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.Marker import com.google.android.gms.maps.model.Marker
import com.google.android.gms.maps.model.MarkerOptions
import com.google.android.gms.maps.model.PolylineOptions
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
...@@ -51,6 +49,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea ...@@ -51,6 +49,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
private var myMarker: Marker? = null private var myMarker: Marker? = null
private var friendMarker: Marker? = null private var friendMarker: Marker? = null
private var currentViewingBean: ViewingBean? = null
override fun initView() { override fun initView() {
...@@ -74,9 +73,13 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea ...@@ -74,9 +73,13 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
private fun initAdapter() { private fun initAdapter() {
adapter = ViewingAdapter() adapter = ViewingAdapter {
if (currentViewingBean != it) {
currentViewingBean = it
initFriendLocationMarker(it)
}
}
binding.rvViewing.adapter = adapter binding.rvViewing.adapter = adapter
} }
private fun showFriendGuideOrNoFriend() { private fun showFriendGuideOrNoFriend() {
...@@ -106,6 +109,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea ...@@ -106,6 +109,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
) )
} }
override fun initListener() { override fun initListener() {
super.initListener() super.initListener()
if (isLanguageRecreate(MyApplication.locationMapLanguage)) { if (isLanguageRecreate(MyApplication.locationMapLanguage)) {
...@@ -135,14 +139,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea ...@@ -135,14 +139,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
} }
binding.ivLocation.setOnClickListener { binding.ivLocation.setOnClickListener {
val i = 2 resetMyLocation()
if (i == 2) {
val chunxilu = LatLng(30.655782251943407, 104.07701072527895)
upDateMeAndFriendLocation(chunxilu)
} else {
resetMyLocation()
}
} }
binding.ivRefresh.setOnClickListener { binding.ivRefresh.setOnClickListener {
startRefreshAnimation() startRefreshAnimation()
...@@ -150,6 +147,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea ...@@ -150,6 +147,7 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
delay(2000) delay(2000)
stopRefreshAnimation() stopRefreshAnimation()
} }
initViewingData()
} }
binding.bottomSheet.setOnClickListener { } binding.bottomSheet.setOnClickListener { }
...@@ -181,127 +179,58 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea ...@@ -181,127 +179,58 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
override fun onMapReady(googleMap: GoogleMap) { override fun onMapReady(googleMap: GoogleMap) {
map = googleMap map = googleMap
LogEx.logDebug(TAG, "onMapReady") LogEx.logDebug(TAG, "onMapReady")
val sydney = LatLng(-33.87365, 151.20689) initMyLocationMarker()
val chunxilu = LatLng(30.655782251943407, 104.07701072527895) resetMyLocation()
initMyAndFriendLocation(chunxilu)
// sharingLocationJob()
} }
private fun resetMyLocation() { private fun resetMyLocation() {
val myLatLng: LatLng = getLastKnowLatLng() var myLatLng: LatLng? = getLatLngByLocationManager()
myMarker?.position = myLatLng if (myLatLng == null) {
map?.moveCamera(CameraUpdateFactory.newLatLngZoom(myLatLng, 15f)) myLatLng = locationPresenter.googleLocation
} }
if (BuildConfig.DEBUG) {
private fun initMyAndFriendLocation(friendLatLng: LatLng) { if (myLatLng == null) {
toast("can't get LatLng")
val myLatLng: LatLng = getLastKnowLatLng()
LogEx.logDebug(TAG, "getLastKnowLocation ${myLatLng.latitude} ${myLatLng.longitude}")
val myAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_me, null)
val friendAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_friend, null)
myMarker = map?.addLocationMarker(myAvatar, myLatLng, "my")
friendMarker = map?.addLocationMarker(friendAvatar, friendLatLng, "friend")
val padding = resources.getDimensionPixelOffset(R.dimen.dp_150)
map?.cameraMovePointsBounds(myLatLng, friendLatLng, padding)
// val list = arrayListOf<LatLng>()
// list.addAll(friendTestLine)
// list.add(friendLatLng)
// addFriendPolyline(list)
}
private fun upDateMeAndFriendLocation(friendLatLng: LatLng) {
val myLatLng: LatLng = getLastKnowLatLng()
myMarker?.position = myLatLng
friendMarker?.position = friendLatLng
val padding = resources.getDimensionPixelOffset(R.dimen.dp_150)
map?.cameraMovePointsBounds(myLatLng, friendLatLng, padding)
}
val friendTestLine = listOf(
LatLng(30.65988197028939, 104.07775588286886),//總府皇冠假日酒店
LatLng(30.658174607262318, 104.06581096754789),//天府广场
LatLng(30.6531557462031, 104.06660595172475),//航天科技大廈
LatLng(30.64867742925485, 104.06548317653692),//錦江賓館
LatLng(30.654908885860806, 104.08053620625755),//ifs
)
fun rotateMarker() {
val myAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_me, null)
val myPair: LatLng = getLastKnowLatLng()
val bitmapDescriptor = BitmapUtils.getBitmapDescriptorFromLayoutResId(myAvatar)
val marker: Marker? = map?.addMarker(
MarkerOptions()
.icon(bitmapDescriptor)
.position(myPair)
.anchor(0.5f, 0.5f) // 设置锚点为中心
.rotation(90.0f) // 设置旋转角度
.flat(true)
) // 设置为平面Marker
lifecycleScope.launch {
for (i in 0..360) {
marker?.rotation = i.toFloat()
delay(200)
} }
} }
initMyLocationMarker()
myLatLng?.let {
myMarker?.position = myLatLng
map?.moveCamera(CameraUpdateFactory.newLatLngZoom(myLatLng, 15f))
}
} }
fun addFriendPolyline(list: List<LatLng>) { private fun initMyLocationMarker() {
map?.addPolyline(PolylineOptions().apply { if (myMarker == null) {
list.forEach { add(it) } var myLatLng: LatLng? = getLatLngByLocationManager()
width(5.toFloat()) if (myLatLng == null) {
color(Color.BLUE) myLatLng = locationPresenter.googleLocation
geodesic(true) }
clickable(true) myLatLng?.let {
}) LogEx.logDebug(TAG, "getLastKnowLocation ${myLatLng.latitude} ${myLatLng.longitude}")
} val myAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_me, null)
myMarker = map?.addLocationMarker(myAvatar, myLatLng, getString(R.string.me))
private var sharingJob: Job? = null
fun sharingLocationJob() {
if (sharingJob == null) {
myMarker ?: return
friendMarker ?: return
var i = 0f
var j = 0f
sharingJob = lifecycleScope.launch {
while (isActive) {
i += 0.001f
j += 0.001f
val myLatLng = getLastKnowLatLng()
myMarker?.position = myLatLng
//上传我的位置,获取friend位置
val friendLatLng = LatLng(30.655782251943407 + i, 104.07701072527895 + j)
friendMarker?.position = friendLatLng
delay(1 * 1000L)
}
} }
} }
} }
private fun cancelSharingJob() { private fun initFriendLocationMarker(viewingBean: ViewingBean) {
sharingJob?.cancel() if (friendMarker != null) {
sharingJob = null friendMarker?.remove()
friendMarker = null
}
val friendAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_friend, null)
viewingBean.locatDate?.let {
val latLng = LatLng(viewingBean.locatDate.latitude, viewingBean.locatDate.longitude)
friendMarker = map?.addLocationMarker(friendAvatar, latLng, viewingBean.nickname)
map?.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15f))
}
} }
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
cancelSharingJob()
locationPresenter.cancelUploadJob() locationPresenter.cancelUploadJob()
} }
......
package com.base.locationsharewhite.ui.locationmap package com.base.locationsharewhite.ui.locationmap
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context import android.content.Context
import android.location.Location
import androidx.lifecycle.LifecycleCoroutineScope import androidx.lifecycle.LifecycleCoroutineScope
import com.base.locationsharewhite.location.LocationPositionUtils import com.base.locationsharewhite.helper.BaseActivity
import com.base.locationsharewhite.location.LocationPositionUtils.uploadMyLocation import com.base.locationsharewhite.location.LocationPositionUtils.uploadMyLocation
import com.base.locationsharewhite.map.MapUtils.getLastKnowLatLng import com.base.locationsharewhite.map.MapUtils.getLatLngByLocationManager
import com.base.locationsharewhite.utils.BatteryUtils.getBatteryLevel import com.base.locationsharewhite.utils.BatteryUtils.getBatteryLevel
import com.base.locationsharewhite.utils.LogEx import com.base.locationsharewhite.utils.LogEx
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.gms.maps.model.LatLng
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
...@@ -14,26 +20,47 @@ import kotlinx.coroutines.isActive ...@@ -14,26 +20,47 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class LocationPresenter( class LocationPresenter(
val context: Context, val activity: Activity,
val lifecycleCoroutineScope: LifecycleCoroutineScope val lifecycleCoroutineScope: LifecycleCoroutineScope
) { ) {
private var TAG = "LocationPresenter" private var TAG = "LocationPresenter"
private var uploadJob: Job? = null private var uploadJob: Job? = null
//google的地理位置服务
private var fusedLocationClient: FusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(activity)
var googleLocation: LatLng? = null
fun startUploadMyLocation() { fun startUploadMyLocation() {
if (uploadJob == null) { if (uploadJob == null) {
LogEx.logDebug(TAG,"startUploadMyLocation") LogEx.logDebug(TAG, "startUploadMyLocation")
uploadJob = lifecycleCoroutineScope.launch(Dispatchers.IO) { uploadJob = lifecycleCoroutineScope.launch(Dispatchers.IO) {
while (isActive) { while (isActive) {
val latLng = context.getLastKnowLatLng() getGoogleServiceLocation()
val power = context.getBatteryLevel()
uploadMyLocation(latLng, power) var latLng = activity.getLatLngByLocationManager()
if (latLng == null) {
latLng = googleLocation
}
val power = activity.getBatteryLevel()
latLng?.let { uploadMyLocation(latLng, power) }
delay(30 * 1000L) delay(30 * 1000L)
} }
} }
} }
} }
@SuppressLint("MissingPermission")
fun getGoogleServiceLocation() {
fusedLocationClient.lastLocation
.addOnSuccessListener { location: Location? ->
if (location != null) {
googleLocation = LatLng(location.latitude, location.longitude)
}
}
}
fun cancelUploadJob() { fun cancelUploadJob() {
uploadJob?.cancel() uploadJob?.cancel()
uploadJob = null uploadJob = null
......
...@@ -8,15 +8,43 @@ import com.base.locationsharewhite.R ...@@ -8,15 +8,43 @@ import com.base.locationsharewhite.R
import com.base.locationsharewhite.bean.ViewingBean import com.base.locationsharewhite.bean.ViewingBean
import com.base.locationsharewhite.databinding.ItemViewingBinding import com.base.locationsharewhite.databinding.ItemViewingBinding
import com.base.locationsharewhite.ui.views.XmlEx.inflate import com.base.locationsharewhite.ui.views.XmlEx.inflate
import com.base.locationsharewhite.utils.KotlinExt.toFormatHHMinute
import com.chad.library.adapter4.BaseQuickAdapter import com.chad.library.adapter4.BaseQuickAdapter
class ViewingAdapter : BaseQuickAdapter<ViewingBean, ViewingAdapter.ViewingViewHolder>() { class ViewingAdapter(val itemClick: (item: ViewingBean) -> Unit) : BaseQuickAdapter<ViewingBean, ViewingAdapter.ViewingViewHolder>() {
inner class ViewingViewHolder(view: View) : ViewHolder(view) inner class ViewingViewHolder(view: View) : ViewHolder(view)
override fun onBindViewHolder(holder: ViewingViewHolder, position: Int, item: ViewingBean?) { override fun onBindViewHolder(holder: ViewingViewHolder, position: Int, item: ViewingBean?) {
item ?: return item ?: return
val binding = ItemViewingBinding.bind(holder.itemView) val binding = ItemViewingBinding.bind(holder.itemView)
binding.tvNameLetters.text = item.nickname.substring(0, 1) binding.tvNameLetters.text = item.nickname.substring(0, 1)
binding.tvNameCode.text = item.nickname binding.tvNameCode.text = item.nickname
when (item.locatDate?.power) {
in 0..20 -> {
binding.ivPower.setImageResource(R.mipmap.dianchi5)
}
in 21..40 -> {
binding.ivPower.setImageResource(R.mipmap.dianchi4)
}
in 41..60 -> {
binding.ivPower.setImageResource(R.mipmap.dianchi3)
}
in 61..80 -> {
binding.ivPower.setImageResource(R.mipmap.dianchi2)
}
in 81..100 -> {
binding.ivPower.setImageResource(R.mipmap.dianchi1)
}
}
val time = item.locatDate?.timezone ?: 0
binding.tvTime.text = time.toFormatHHMinute()
binding.root.setOnClickListener {
itemClick.invoke(item)
}
} }
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): ViewingViewHolder { override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): ViewingViewHolder {
......
package com.base.locationsharewhite.ui.locationmap
//import android.graphics.Color
//import android.view.LayoutInflater
//import androidx.lifecycle.lifecycleScope
//import com.base.locationsharewhite.R
//import com.base.locationsharewhite.map.MapUtils.cameraMovePointsBounds
//import com.base.locationsharewhite.utils.BitmapUtils
//import com.google.android.gms.maps.model.LatLng
//import com.google.android.gms.maps.model.Marker
//import com.google.android.gms.maps.model.MarkerOptions
//import com.google.android.gms.maps.model.PolylineOptions
//import kotlinx.coroutines.Job
//import kotlinx.coroutines.delay
//import kotlinx.coroutines.isActive
//import kotlinx.coroutines.launch
//val friendTestLine = listOf(
// LatLng(30.65988197028939, 104.07775588286886),//總府皇冠假日酒店
// LatLng(30.658174607262318, 104.06581096754789),//天府广场
// LatLng(30.6531557462031, 104.06660595172475),//航天科技大廈
// LatLng(30.64867742925485, 104.06548317653692),//錦江賓館
// LatLng(30.654908885860806, 104.08053620625755),//ifs
//)
//
//fun rotateMarker() {
//
// val myAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_me, null)
//
// val myPair: LatLng = getLastKnowLatLng()
// val bitmapDescriptor = BitmapUtils.getBitmapDescriptorFromLayoutResId(myAvatar)
//
// val marker: Marker? = map?.addMarker(
// MarkerOptions()
// .icon(bitmapDescriptor)
// .position(myPair)
// .anchor(0.5f, 0.5f) // 设置锚点为中心
// .rotation(90.0f) // 设置旋转角度
// .flat(true)
// ) // 设置为平面Marker
//
// lifecycleScope.launch {
// for (i in 0..360) {
// marker?.rotation = i.toFloat()
// delay(200)
// }
// }
//}
//
//fun addFriendPolyline(list: List<LatLng>) {
// map?.addPolyline(PolylineOptions().apply {
// list.forEach { add(it) }
// width(5.toFloat())
// color(Color.BLUE)
// geodesic(true)
// clickable(true)
// })
//}
//private fun upDateMeAndFriendLocation(friendLatLng: LatLng) {
// val myLatLng: LatLng = getLastKnowLatLng()
// myMarker?.position = myLatLng
// friendMarker?.position = friendLatLng
// val padding = resources.getDimensionPixelOffset(R.dimen.dp_150)
// map?.cameraMovePointsBounds(myLatLng, friendLatLng, padding)
//}
//private var sharingJob: Job? = null
//fun sharingLocationJob() {
// if (sharingJob == null) {
//
// myMarker ?: return
// friendMarker ?: return
//
// var i = 0f
// var j = 0f
// sharingJob = lifecycleScope.launch {
// while (isActive) {
// i += 0.001f
// j += 0.001f
//
// val myLatLng = getLastKnowLatLng()
// myMarker?.position = myLatLng
// //上传我的位置,获取friend位置
// val friendLatLng = LatLng(30.655782251943407 + i, 104.07701072527895 + j)
// friendMarker?.position = friendLatLng
//
// delay(1 * 1000L)
// }
// }
// }
//}
//private fun cancelSharingJob() {
// sharingJob?.cancel()
// sharingJob = null
//}
\ No newline at end of file
...@@ -13,7 +13,7 @@ import com.base.locationsharewhite.helper.BaseActivity ...@@ -13,7 +13,7 @@ import com.base.locationsharewhite.helper.BaseActivity
import com.base.locationsharewhite.helper.MyApplication import com.base.locationsharewhite.helper.MyApplication
import com.base.locationsharewhite.location.LocationLoginUtils import com.base.locationsharewhite.location.LocationLoginUtils
import com.base.locationsharewhite.map.MapUtils.addLocationMarker import com.base.locationsharewhite.map.MapUtils.addLocationMarker
import com.base.locationsharewhite.map.MapUtils.getLastKnowLatLng import com.base.locationsharewhite.map.MapUtils.getLatLngByLocationManager
import com.base.locationsharewhite.ui.howuse.HowUseActivity import com.base.locationsharewhite.ui.howuse.HowUseActivity
import com.base.locationsharewhite.ui.locationmap.LocationMapActivity import com.base.locationsharewhite.ui.locationmap.LocationMapActivity
import com.base.locationsharewhite.ui.set.SettingActivity import com.base.locationsharewhite.ui.set.SettingActivity
...@@ -112,12 +112,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnMapReadyCallback { ...@@ -112,12 +112,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnMapReadyCallback {
override fun onMapReady(googleMap: GoogleMap) { override fun onMapReady(googleMap: GoogleMap) {
map = googleMap map = googleMap
val latLng = getLastKnowLatLng() val latLng = getLatLngByLocationManager()
LogEx.logDebug(TAG, "getLastKnowLocation ${latLng.latitude} ${latLng.longitude}") latLng?.let {
LogEx.logDebug(TAG, "getLastKnowLocation ${latLng.latitude} ${latLng.longitude}")
val myAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_me, null) val myAvatar = LayoutInflater.from(this).inflate(R.layout.avatar_me, null)
map?.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15f))
map?.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15f)) map?.addLocationMarker(myAvatar, latLng, "my")
map?.addLocationMarker(myAvatar, latLng, "my") }
} }
} }
\ No newline at end of file
...@@ -44,6 +44,10 @@ object KotlinExt { ...@@ -44,6 +44,10 @@ object KotlinExt {
return SimpleDateFormat("mm", Locale.ENGLISH).format(this) return SimpleDateFormat("mm", Locale.ENGLISH).format(this)
} }
fun Long.toFormatHHMinute(): String {
return SimpleDateFormat("HH:mm", Locale.ENGLISH).format(this)
}
fun Array<String>.array2String(): String { fun Array<String>.array2String(): String {
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
......
...@@ -37,17 +37,18 @@ ...@@ -37,17 +37,18 @@
</FrameLayout> </FrameLayout>
<LinearLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginHorizontal="8dp" android:layout_marginStart="8dp"
android:layout_marginEnd="24dp"
android:layout_weight="1" android:layout_weight="1"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/tv_name_code" android:id="@+id/tv_name_code"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end" android:ellipsize="end"
android:includeFontPadding="false" android:includeFontPadding="false"
...@@ -55,17 +56,45 @@ ...@@ -55,17 +56,45 @@
android:textColor="#001725" android:textColor="#001725"
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@id/tv_time"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="V0OC3RJK" /> tools:text="V0OC3RJK" />
<TextView <TextView
android:id="@+id/tv_time" android:id="@+id/tv_time"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginHorizontal="8dp"
android:includeFontPadding="false"
android:textColor="#81888D" android:textColor="#81888D"
android:textSize="14sp" android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="@id/tv_name_code"
app:layout_constraintEnd_toStartOf="@id/iv_power"
app:layout_constraintStart_toEndOf="@id/tv_name_code"
app:layout_constraintTop_toTopOf="@id/tv_name_code"
tools:text="20:27" /> tools:text="20:27" />
</LinearLayout>
<ImageView
android:id="@+id/iv_power"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/dianchi1"
app:layout_constraintBottom_toBottomOf="@id/tv_name_code"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tv_time"
app:layout_constraintTop_toTopOf="@id/tv_name_code"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="18dp"
android:src="@mipmap/shoucang_n"
tools:ignore="ContentDescription" />
<ImageView <ImageView
......
...@@ -53,4 +53,5 @@ ...@@ -53,4 +53,5 @@
<string name="a_simple_name_can_make_nothers_find_you_faster">A simple name can make\nothers find you faster!</string> <string name="a_simple_name_can_make_nothers_find_you_faster">A simple name can make\nothers find you faster!</string>
<string name="enter_your_name">Enter your name</string> <string name="enter_your_name">Enter your name</string>
<string name="name_is_empty">Name is empty</string> <string name="name_is_empty">Name is empty</string>
<string name="me">me</string>
</resources> </resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment