@@ -17,13 +17,16 @@ import java.util.Date
17
17
18
18
@AndroidEntryPoint
19
19
internal class RunningActivity :
20
- BaseActivity <ActivityRunningBinding >(R .layout.activity_running), OnMapReadyCallback {
20
+ BaseActivity <ActivityRunningBinding >(R .layout.activity_running),
21
+ OnMapReadyCallback ,
22
+ LocationSource {
21
23
22
24
private val viewModel: RunningViewModel by viewModels()
23
25
24
26
private lateinit var mapView: MapView
25
27
private lateinit var naverMap: NaverMap
26
28
private lateinit var paths: MutableList <PathOverlay >
29
+ private var listener: LocationSource .OnLocationChangedListener ? = null
27
30
28
31
override fun onCreate (savedInstanceState : Bundle ? ) {
29
32
super .onCreate(savedInstanceState)
@@ -36,10 +39,13 @@ internal class RunningActivity :
36
39
this .naverMap = naverMap
37
40
38
41
with (naverMap) {
42
+ locationSource = this @RunningActivity
39
43
maxZoom = MAP_MAX_ZOOM
40
44
minZoom = MAP_MIN_ZOOM
41
- uiSettings.isLocationButtonEnabled = false
45
+ uiSettings.isCompassEnabled = false
42
46
uiSettings.isZoomControlEnabled = false
47
+ uiSettings.isLocationButtonEnabled = false
48
+ uiSettings.setLogoMargin(0 , 0 , 0 , - 10 )
43
49
locationOverlay.isVisible = true
44
50
locationOverlay.icon = OverlayImage .fromResource(R .drawable.kong)
45
51
locationOverlay.iconWidth = MAP_ICON_SIZE
@@ -92,6 +98,14 @@ internal class RunningActivity :
92
98
mapView.onLowMemory()
93
99
}
94
100
101
+ override fun activate (listener : LocationSource .OnLocationChangedListener ) {
102
+ this .listener = listener
103
+ }
104
+
105
+ override fun deactivate () {
106
+ this .listener = null
107
+ }
108
+
95
109
private fun initViews (savedInstanceState : Bundle ? ) {
96
110
mapView = binding.mapView
97
111
@@ -129,8 +143,16 @@ internal class RunningActivity :
129
143
}
130
144
131
145
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
+ }
134
156
}
135
157
}
136
158
0 commit comments