Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

재검색 최대 좌표 설정 #84

Merged
merged 8 commits into from
Jan 21, 2024

Conversation

SungMinCho-Kor
Copy link
Contributor

@SungMinCho-Kor SungMinCho-Kor commented Jan 20, 2024

⭐️ Issue Number

🚩 Summary

  • 최대 위도 경도 좌표 설정
  • 회전에 대응
image image

🛠️ Technical Concerns

너무 많은 데이터 전달로 인한 앱 멈춤

사용자가 지도를 조작하여 줌아웃을 해서 대한민국 전체로 재검색을 한다면 5만개 이상의 객체를 받아오게 된다.
그렇기 때문에 멈춤 현상과 과도한 데이터 전송이 일어난다.
이를 방지하기 위해서 재검색 최대 크기를 설정했다.
사용자가 특정 수치 이상 줌 아웃한 상태에서 재검색을 하면 요청 좌표 4개가 작은 크기로 재설정되도록 하여 해결했다.

회전에 대응하는 로직

좌표 4개를 수정하는 과정에서 위도 경도와 관련하여 로직 이슈가 있었다.

image

파란 점을 노란 점으로 옮겨야 했다.

location1과 location4 길이 d1, location1과 location2 길이 d2

if d1 > 0.7
세로 수정 -> 파란색 점에서 보라색 점으로 변경
if d2 > 0.7 (세로 가로 모두 수정)
가로 수정 -> 보라색 점에서 노랑색 점으로 변경
if d1 < 0.7 (수정 필요 없음)
그대로 

항상 d1 > d2 이기 때문에 가로만 수정되는 경우는 없다.

이제 수학적으로 점을 옮겨야 했다.
점과 직선 사이의 거리 공식, 직선의 방정식이, 직선의 평행이동 등의 수학적 지식이 필요했다.

  1. location1과 location2를 이용하여 기울기를 구한다. (기울기 m)
  2. 기울기가 m이고 center와의 거리가 원하는 최대 크기 0.07의 절반인 0.035인 직선을 구한다. (직선은 2개 나온다)
  3. 기울기가 m과 수직이고 location1을 지나는 직선이 위에서 구한 직선 두개와 만나는 점을 구한다.
  4. 기울기가 m과 수직이고 location2을 지나는 직선이 위에서 구한 직선 두개와 만나는 점을 구한다.

이렇게 4가지가 나오면 보라색 점을 구할 수 있다.
이 보라색 점 4개중 다른 방향으로 로직을 한번 더 실행하면 노랑색 점을 구할 수 있다.

기울기를 구하는 과정에서 기울기가 0이 되거나 무한대가 되는 상황은 예외처리로 해결했다.

📋 To Do

  • Location의 순서를 하나로 정해야 한다.

@SungMinCho-Kor SungMinCho-Kor added the ✨ Feature 기능 관련 작업 label Jan 20, 2024
@SungMinCho-Kor SungMinCho-Kor requested a review from k2645 January 20, 2024 19:35
@SungMinCho-Kor SungMinCho-Kor self-assigned this Jan 20, 2024
@SungMinCho-Kor SungMinCho-Kor linked an issue Jan 20, 2024 that may be closed by this pull request
Copy link
Contributor

@k2645 k2645 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정말 좋은 트러블 슈팅이었던 것 같습니다.
수식을 작성하고 figma로 직접 그림까지 그려주셔서 로직을 이해하는데 정말 많은 도움이 되었습니다.
수고하셨습니다👍

static let storeURL = "http://13.124.127.77:8080/api/v1/storecertification/byLocation"
static let storeURL = "http://35.216.42.117:8080/api/v1/storecertification/byLocation"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prod URL과 dev URL을 열거형으로 저장해두는건 어떨까요?
서버와 연결되는 URL을 항상 확인해서 무슨 URL을 사용하는지 확인해야하는 번거로움을 줄일 수 있을것 같습니다.

Comment on lines 80 to 98
let newNorthWest = Location(
longitude: (loc1.latitude + (loc1.longitude / slope) - constant1) / (slope + 1 / slope),
latitude: (slope * loc1.latitude + loc1.longitude + constant1 / slope) / (slope + 1 / slope)
)

let newNorthEast = Location(
longitude: (loc2.latitude + (loc2.longitude / slope) - constant1) / (slope + 1 / slope),
latitude: (slope * loc2.latitude + loc2.longitude + constant1 / slope) / (slope + 1 / slope)
)

let newSouthEast = Location(
longitude: (loc2.latitude + (loc2.longitude / slope) - constant2) / (slope + 1 / slope),
latitude: (slope * loc2.latitude + loc2.longitude + constant2 / slope) / (slope + 1 / slope)
)

let newSouthWest = Location(
longitude: (loc1.latitude + (loc1.longitude / slope) - constant2) / (slope + 1 / slope),
latitude: (slope * loc1.latitude + loc1.longitude + constant2 / slope) / (slope + 1 / slope)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

중복되는 로직인 것 같은데 함수화를 하면 좋을 것 같습니다.

Comment on lines +58 to +71
if loc1.latitude == loc2.latitude {
return RequestLocation(
northWest: Location(longitude: loc1.longitude, latitude: center.latitude + 0.035),
southWest: Location(longitude: loc1.longitude, latitude: center.latitude - 0.035),
southEast: Location(longitude: loc2.longitude, latitude: center.latitude - 0.035),
northEast: Location(longitude: loc2.longitude, latitude: center.latitude + 0.035)
)
} else if loc1.longitude == loc2.longitude {
return RequestLocation(
northWest: Location(longitude: center.longitude + 0.035, latitude: loc1.latitude),
southWest: Location(longitude: center.longitude - 0.035, latitude: loc1.latitude),
southEast: Location(longitude: center.longitude - 0.035, latitude: loc2.latitude),
northEast: Location(longitude: center.longitude + 0.035, latitude: loc2.latitude)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로직이 기울기가 무한이나 0이 나오는 경우를 예외처리하는 로직인 것 같은데 어떻게 처리되는건지 설명해주시면 감사하겠습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가운데를 기준으로 0.035의 크기로 가로 세로 길이를 수정하는 로직입니다.

@SungMinCho-Kor SungMinCho-Kor requested a review from k2645 January 21, 2024 06:57
Copy link
Contributor

@k2645 k2645 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

do {
return try getURL(type: .develop)
} catch {
return ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 메소드에서 error를 날렸을 때 NetworkError.wrongURL를 던졌는데 해당 에러를 log에 표시해주는 코드를 짜주면 좋을 것 같습니다.

@SungMinCho-Kor SungMinCho-Kor requested a review from k2645 January 21, 2024 07:03
Copy link
Contributor

@k2645 k2645 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다 ~

@SungMinCho-Kor SungMinCho-Kor merged commit 89e0383 into develop Jan 21, 2024
@SungMinCho-Kor SungMinCho-Kor deleted the feature/max-refresh-location(#74) branch January 21, 2024 07:04
@SungMinCho-Kor SungMinCho-Kor added this to the 1.0 milestone Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature 기능 관련 작업
Projects
None yet
Development

Successfully merging this pull request may close these issues.

재검색 최대 좌표 설정
2 participants