Skip to content

Commit 6567965

Browse files
bngshyonghanJu
andcommitted
✨ 네이버맵 locationOverlay 및 커스텀 LocationSource 구현
Co-authored-by: yonghanJu <[email protected]>
1 parent 09e8a7b commit 6567965

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

presentation/src/main/java/com/whyranoid/presentation/running/RunningActivity.kt

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ import java.util.Date
1717

1818
@AndroidEntryPoint
1919
internal class RunningActivity :
20-
BaseActivity<ActivityRunningBinding>(R.layout.activity_running), OnMapReadyCallback {
20+
BaseActivity<ActivityRunningBinding>(R.layout.activity_running),
21+
OnMapReadyCallback,
22+
LocationSource {
2123

2224
private val viewModel: RunningViewModel by viewModels()
2325

2426
private lateinit var mapView: MapView
2527
private lateinit var naverMap: NaverMap
2628
private lateinit var paths: MutableList<PathOverlay>
29+
private var listener: LocationSource.OnLocationChangedListener? = null
2730

2831
override fun onCreate(savedInstanceState: Bundle?) {
2932
super.onCreate(savedInstanceState)
@@ -36,10 +39,13 @@ internal class RunningActivity :
3639
this.naverMap = naverMap
3740

3841
with(naverMap) {
42+
locationSource = this@RunningActivity
3943
maxZoom = MAP_MAX_ZOOM
4044
minZoom = MAP_MIN_ZOOM
41-
uiSettings.isLocationButtonEnabled = false
45+
uiSettings.isCompassEnabled = false
4246
uiSettings.isZoomControlEnabled = false
47+
uiSettings.isLocationButtonEnabled = false
48+
uiSettings.setLogoMargin(0, 0, 0, -10)
4349
locationOverlay.isVisible = true
4450
locationOverlay.icon = OverlayImage.fromResource(R.drawable.kong)
4551
locationOverlay.iconWidth = MAP_ICON_SIZE
@@ -92,6 +98,14 @@ internal class RunningActivity :
9298
mapView.onLowMemory()
9399
}
94100

101+
override fun activate(listener: LocationSource.OnLocationChangedListener) {
102+
this.listener = listener
103+
}
104+
105+
override fun deactivate() {
106+
this.listener = null
107+
}
108+
95109
private fun initViews(savedInstanceState: Bundle?) {
96110
mapView = binding.mapView
97111

@@ -129,8 +143,16 @@ internal class RunningActivity :
129143
}
130144

131145
private fun updateRunnerPosition(runningState: RunningState) {
132-
runningState.runningData.runningPositionList.last().lastOrNull()?.let {
133-
naverMap.locationOverlay.position = it.toLatLng()
146+
runningState.runningData.lastLocation?.let { location ->
147+
listener?.onLocationChanged(location) ?: run {
148+
naverMap.let {
149+
val locationOverlay = it.locationOverlay
150+
locationOverlay.isVisible = true
151+
locationOverlay.position = LatLng(location)
152+
locationOverlay.bearing = (locationOverlay.bearing + 30) % 360
153+
locationOverlay.circleRadius = 100
154+
}
155+
}
134156
}
135157
}
136158

presentation/src/main/java/com/whyranoid/presentation/running/RunningRepository.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ class RunningRepository @Inject constructor() {
6767
finishData
6868
}
6969

70-
fun setRunningState(runningPosition: RunningPosition) {
70+
fun setRunningState(location: Location) {
7171
if (_runningState.value is RunningState.Running) {
72+
val runningPosition = RunningPosition(location.latitude, location.longitude)
7273
val prevRunningData = _runningState.value.runningData
7374
val newRunningTime = prevRunningData.runningTime
7475
val distance = FloatArray(1)
@@ -94,7 +95,8 @@ class RunningRepository @Inject constructor() {
9495
runningTime = newRunningTime,
9596
totalDistance = newTotalDistance,
9697
pace = newPace,
97-
runningPositionList = newRunningPositionList
98+
runningPositionList = newRunningPositionList,
99+
lastLocation = location
98100
)
99101
)
100102
}
@@ -113,7 +115,8 @@ data class RunningData(
113115
val runningTime: Int = 0,
114116
val totalDistance: Double = 0.0,
115117
val pace: Double = 0.0,
116-
val runningPositionList: List<List<RunningPosition>> = listOf(emptyList())
118+
val runningPositionList: List<List<RunningPosition>> = listOf(emptyList()),
119+
val lastLocation: Location? = null
117120
)
118121

119122
data class RunningFinishData(

0 commit comments

Comments
 (0)