Skip to content

Commit

Permalink
[#133] 리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean9701 authored and 00yhsp committed Nov 20, 2024
1 parent 0356e40 commit 1cc76ac
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions AGAMI/Sources/Service/Location/LocationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,38 @@ final class LocationService: NSObject {
}
})
}
}

func coordinateToStreetAddress() async -> String? {
guard let currentLocation else { return nil }
return await withCheckedContinuation { continuation in
let geocoder = CLGeocoder()
let locale = Locale(identifier: "ko_KR")

geocoder.reverseGeocodeLocation(currentLocation, preferredLocale: locale) { [weak self] (placemarks, _) in
guard let self = self else { return }
if let address = placemarks?.last {
var currentAddress = ""

if let name = address.name {
currentAddress += name
self.placeHolderAddress = name
self.region = name
}

if let area = address.locality {
currentAddress += ", \(area)"
self.locality = area
}

self.streetAddress = currentAddress
continuation.resume(returning: currentAddress)
} else {
continuation.resume(returning: nil)
}
}
}
}
}

extension LocationService: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
Expand Down Expand Up @@ -123,36 +154,3 @@ extension LocationService: CLLocationManagerDelegate {
}
}
}

extension LocationService {
func coordinateToStreetAddress() async -> String? {
guard let currentLocation else { return nil }
return await withCheckedContinuation { continuation in
let geocoder = CLGeocoder()
let locale = Locale(identifier: "ko_KR")

geocoder.reverseGeocodeLocation(currentLocation, preferredLocale: locale) { [weak self] (placemarks, _) in
guard let self = self else { return }
if let address = placemarks?.last {
var currentAddress = ""

if let name = address.name {
currentAddress += name
self.placeHolderAddress = name
self.region = name
}

if let area = address.locality {
currentAddress += ", \(area)"
self.locality = area
}

self.streetAddress = currentAddress
continuation.resume(returning: currentAddress)
} else {
continuation.resume(returning: nil)
}
}
}
}
}

0 comments on commit 1cc76ac

Please sign in to comment.