Commit f5a0f47e authored by wanglei's avatar wanglei

init

parent e2df39b5
......@@ -22,7 +22,9 @@ 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
......@@ -83,9 +85,10 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
val chunxilu = LatLng(30.655782251943407, 104.07701072527895)
initMyAndFriendLocation(chunxilu)
sharingLocationJob()
}
fun resetMyLocation() {
private fun resetMyLocation() {
val myLatLng: LatLng = getLastKnowLatLng()
myMarker?.position = myLatLng
map?.moveCamera(CameraUpdateFactory.newLatLngZoom(myLatLng, 15f))
......@@ -162,4 +165,41 @@ class LocationMapActivity : BaseActivity<ActivityLocationMapBinding>(), OnMapRea
})
}
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
}
override fun onPause() {
super.onPause()
cancelSharingJob()
}
}
\ 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