Skip to content

Commit

Permalink
✨ 실시간 Polyline 필터링 시 5m 이하의 값 필터링 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
yoondj98 committed Dec 13, 2023
1 parent f8d9de9 commit ab477a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,9 @@ extension MapViewController: CLLocationManagerDelegate {
let coordinate2D = CLLocationCoordinate2D(latitude: newCurrentLocation.coordinate.latitude,
longitude: newCurrentLocation.coordinate.longitude)
recordJourneyViewModel.trigger(.fiveLocationsDidRecorded(coordinate2D))

// filtering된 위치 정보가 있을 경우(5개의 위치 데이터가 들어와 필터링이 완료되었을 경우)에만 아래 두 trigger 실행 가능
guard let filteredCoordinate2D = recordJourneyViewModel.state.filteredCoordinate.value else { return }
dump(filteredCoordinate2D)
recordJourneyViewModel.trigger(.locationDidUpdated(filteredCoordinate2D))
recordJourneyViewModel.trigger(.locationsShouldRecorded([filteredCoordinate2D]))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ public final class RecordJourneyViewModel: MapViewModel {
#if DEBUG
MSLogger.make(category: .home).debug("View Did load.")
#endif

/// 이전 currentCoordinate를 previousCoordinate에, 저장할 현재 위치를 currentCoordinate에 update
case .locationDidUpdated(let coordinate):
let previousCoordinate = self.state.currentCoordinate.value
self.state.previousCoordinate.send(previousCoordinate)
self.state.currentCoordinate.send(coordinate)

/// 저장하고 자 하는 위치 데이터를 서버에 전송
case .locationsShouldRecorded(let coordinates):
Task {
let recordingJourney = self.state.recordingJourney.value
Expand All @@ -75,6 +79,7 @@ public final class RecordJourneyViewModel: MapViewModel {
MSLogger.make(category: .home).error("\(error)")
}
}
/// 기록 중에 여정 기록을 취소
case .recordingDidCancelled:
Task {
guard let userID = self.userRepository.fetchUUID() else { return }
Expand All @@ -90,6 +95,7 @@ public final class RecordJourneyViewModel: MapViewModel {
MSLogger.make(category: .home).error("\(error)")
}
}
/// 업데이트되는 위치 정보를 받아와 5개가 될 경우 평균값 필터링 후 저장하는 로직
case .fiveLocationsDidRecorded(let coordinate):
self.filterLongestCoordinate(coordinate: coordinate)
}
Expand All @@ -109,7 +115,11 @@ private extension RecordJourneyViewModel {
}

func filterLongestCoordinate(coordinate: CLLocationCoordinate2D) {

if let previousCoordinate = self.state.previousCoordinate.value {
if calculateDistance(from: previousCoordinate, to: coordinate) <= 5 {
return
}
}
var recordedCoords = self.state.recordedCoordinates.value
recordedCoords.append(coordinate)
self.state.recordedCoordinates.send(recordedCoords)
Expand Down

0 comments on commit ab477a0

Please sign in to comment.