Skip to content

Commit

Permalink
feat: 안심구역 생성 중 현위치로 카메라 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
kyujin0911 committed Jun 20, 2024
1 parent 8626a40 commit e6b9315
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package kr.ac.tukorea.whereareu.presentation.nok

import android.Manifest
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.graphics.PointF
import android.os.Bundle
import android.util.Log
Expand All @@ -17,6 +19,8 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetBehavior.BottomSheetCallback
import com.naver.maps.geometry.LatLng
Expand Down Expand Up @@ -61,6 +65,8 @@ import kr.ac.tukorea.whereareu.util.extension.setInfoWindowText
import kr.ac.tukorea.whereareu.util.extension.setMarker
import kr.ac.tukorea.whereareu.util.extension.setMarkerWithInfoWindow
import kr.ac.tukorea.whereareu.util.extension.setPath
import kr.ac.tukorea.whereareu.util.location.DefaultLocationClient
import kr.ac.tukorea.whereareu.util.location.LocationClient
import kotlin.math.roundToInt


Expand All @@ -85,7 +91,9 @@ class NokMainActivity : BaseActivity<ActivityNokMainBinding>(R.layout.activity_n
private val tag = "NokMainActivity:"
private val isFirstNavigationEvent = mutableListOf(true, true, true)
private var isRequireStopHomeFragmentJob = true
private lateinit var locationSource: FusedLocationSource
//private lateinit var locationSource: FusedLocationSource
private lateinit var locationClient: LocationClient
private lateinit var fusedLocationClient: FusedLocationProviderClient
private fun getUpdateLocationJob(duration: Long): Job {
return lifecycleScope.launch {
while (true) {
Expand Down Expand Up @@ -244,7 +252,10 @@ class NokMainActivity : BaseActivity<ActivityNokMainBinding>(R.layout.activity_n
naverMap?.moveCamera(CameraUpdate.zoomTo(14.0))

with(safeAreMetaData) {
naverMap?.locationSource = locationSource
//getLastKnownLocation()
binding.currentLocationIv.setOnClickListener {
getLastKnownLocation()
}
binding.bottomSheetTopIv.isVisible = false
isSettingSafeArea = true
settingMarker.isVisible = true
Expand Down Expand Up @@ -331,6 +342,25 @@ class NokMainActivity : BaseActivity<ActivityNokMainBinding>(R.layout.activity_n
}
}

private fun getLastKnownLocation() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return
}
fusedLocationClient.lastLocation
.addOnSuccessListener { location ->
if (location != null) {
val latLng = LatLng(location.latitude, location.longitude)
naverMap?.moveCamera(CameraUpdate.scrollTo(latLng))
//locationTextView.text = "Latitude: $latitude, Longitude: $longitude"
} else {
//locationTextView.text = "Location not available"
}
}
.addOnFailureListener { exception ->
Log.d("getLastKnownLocation", exception.message.toString())
}
}

private fun handleNavigationEvent(event: NokHomeViewModel.NavigateEvent) {
when (event) {
NokHomeViewModel.NavigateEvent.Home -> {
Expand Down Expand Up @@ -860,8 +890,9 @@ class NokMainActivity : BaseActivity<ActivityNokMainBinding>(R.layout.activity_n
binding.viewModel = homeViewModel
binding.safeAreaVm = safeAreaViewModel
homeViewModel.fetchUserInfo()
locationSource =
FusedLocationSource(this, LOCATION_PERMISSION_REQUEST_CODE)
//locationSource =
//FusedLocationSource(this, LOCATION_PERMISSION_REQUEST_CODE)
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
initBottomSheet()
initMap()
initNavigator()
Expand Down
10 changes: 10 additions & 0 deletions frontend/app/src/main/res/drawable/ic_gps_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12,1.25C12.199,1.25 12.39,1.329 12.53,1.47C12.671,1.61 12.75,1.801 12.75,2V3.282C14.804,3.459 16.729,4.355 18.187,5.813C19.645,7.271 20.541,9.196 20.718,11.25H22C22.199,11.25 22.39,11.329 22.53,11.47C22.671,11.61 22.75,11.801 22.75,12C22.75,12.199 22.671,12.39 22.53,12.53C22.39,12.671 22.199,12.75 22,12.75H20.718C20.541,14.804 19.645,16.729 18.187,18.187C16.729,19.645 14.804,20.541 12.75,20.718V22C12.75,22.199 12.671,22.39 12.53,22.53C12.39,22.671 12.199,22.75 12,22.75C11.801,22.75 11.61,22.671 11.47,22.53C11.329,22.39 11.25,22.199 11.25,22V20.718C9.196,20.541 7.271,19.645 5.813,18.187C4.355,16.729 3.459,14.804 3.282,12.75H2C1.801,12.75 1.61,12.671 1.47,12.53C1.329,12.39 1.25,12.199 1.25,12C1.25,11.801 1.329,11.61 1.47,11.47C1.61,11.329 1.801,11.25 2,11.25H3.282C3.459,9.196 4.355,7.271 5.813,5.813C7.271,4.355 9.196,3.459 11.25,3.282V2C11.25,1.801 11.329,1.61 11.47,1.47C11.61,1.329 11.801,1.25 12,1.25ZM12,4.75C11.048,4.75 10.105,4.938 9.226,5.302C8.346,5.666 7.547,6.2 6.873,6.873C6.2,7.547 5.666,8.346 5.302,9.226C4.938,10.105 4.75,11.048 4.75,12C4.75,12.952 4.938,13.895 5.302,14.774C5.666,15.654 6.2,16.453 6.873,17.126C7.547,17.8 8.346,18.334 9.226,18.698C10.105,19.063 11.048,19.25 12,19.25C13.923,19.25 15.767,18.486 17.126,17.126C18.486,15.767 19.25,13.923 19.25,12C19.25,10.077 18.486,8.233 17.126,6.873C15.767,5.514 13.923,4.75 12,4.75ZM12,9.75C11.403,9.75 10.831,9.987 10.409,10.409C9.987,10.831 9.75,11.403 9.75,12C9.75,12.597 9.987,13.169 10.409,13.591C10.831,14.013 11.403,14.25 12,14.25C12.597,14.25 13.169,14.013 13.591,13.591C14.013,13.169 14.25,12.597 14.25,12C14.25,11.403 14.013,10.831 13.591,10.409C13.169,9.987 12.597,9.75 12,9.75ZM8.25,12C8.25,11.005 8.645,10.052 9.348,9.348C10.052,8.645 11.005,8.25 12,8.25C12.995,8.25 13.948,8.645 14.652,9.348C15.355,10.052 15.75,11.005 15.75,12C15.75,12.995 15.355,13.948 14.652,14.652C13.948,15.355 12.995,15.75 12,15.75C11.005,15.75 10.052,15.355 9.348,14.652C8.645,13.948 8.25,12.995 8.25,12Z"
android:fillColor="#000000"
android:fillType="evenOdd"/>
</vector>
6 changes: 6 additions & 0 deletions frontend/app/src/main/res/drawable/oval.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/white"/>
<stroke android:width="1dp" android:color="@color/gray20"/>
</shape>
Loading

0 comments on commit e6b9315

Please sign in to comment.