From e6b93152e823f246f25418ec4778426840a63ae6 Mon Sep 17 00:00:00 2001 From: KKJ Date: Thu, 20 Jun 2024 23:53:02 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=95=88=EC=8B=AC=EA=B5=AC=EC=97=AD=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=A4=91=20=ED=98=84=EC=9C=84=EC=B9=98?= =?UTF-8?q?=EB=A1=9C=20=EC=B9=B4=EB=A9=94=EB=9D=BC=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/nok/NokMainActivity.kt | 39 +++++- .../src/main/res/drawable/ic_gps_outline.xml | 10 ++ frontend/app/src/main/res/drawable/oval.xml | 6 + .../src/main/res/layout/activity_nok_main.xml | 126 ++++++++++-------- 4 files changed, 120 insertions(+), 61 deletions(-) create mode 100644 frontend/app/src/main/res/drawable/ic_gps_outline.xml create mode 100644 frontend/app/src/main/res/drawable/oval.xml diff --git a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokMainActivity.kt b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokMainActivity.kt index 48eaae6f..d5c41f2f 100644 --- a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokMainActivity.kt +++ b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokMainActivity.kt @@ -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 @@ -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 @@ -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 @@ -85,7 +91,9 @@ class NokMainActivity : BaseActivity(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) { @@ -244,7 +252,10 @@ class NokMainActivity : BaseActivity(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 @@ -331,6 +342,25 @@ class NokMainActivity : BaseActivity(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 -> { @@ -860,8 +890,9 @@ class NokMainActivity : BaseActivity(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() diff --git a/frontend/app/src/main/res/drawable/ic_gps_outline.xml b/frontend/app/src/main/res/drawable/ic_gps_outline.xml new file mode 100644 index 00000000..5e77e111 --- /dev/null +++ b/frontend/app/src/main/res/drawable/ic_gps_outline.xml @@ -0,0 +1,10 @@ + + + diff --git a/frontend/app/src/main/res/drawable/oval.xml b/frontend/app/src/main/res/drawable/oval.xml new file mode 100644 index 00000000..2d27523e --- /dev/null +++ b/frontend/app/src/main/res/drawable/oval.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/frontend/app/src/main/res/layout/activity_nok_main.xml b/frontend/app/src/main/res/layout/activity_nok_main.xml index 912a1a42..31eaa537 100644 --- a/frontend/app/src/main/res/layout/activity_nok_main.xml +++ b/frontend/app/src/main/res/layout/activity_nok_main.xml @@ -48,8 +48,7 @@ android:name="com.naver.maps.map.MapFragment" android:layout_width="match_parent" android:layout_height="match_parent" - app:navermap_locationButtonEnabled="false" - /> + app:navermap_locationButtonEnabled="false" /> @@ -237,13 +236,13 @@ + app:layout_constraintTop_toTopOf="parent">