@@ -174,14 +174,14 @@ extension TKUIRoutingResultsViewModel {
174174 origin = asObject. rx. observeWeakly ( CLLocationCoordinate2D . self, " coordinate " )
175175 . compactMap { [ weak asObject] _ in asObject? . coordinate }
176176 . distinctUntilChanged ( isCloseEnough)
177- . flatMapLatest { [ weak asObject] _ in RouteBuilder . needAddress ( asObject, retryLimit : 3 , delay : 1 ) }
177+ . flatMapLatest { [ weak asObject] _ in RouteBuilder . needAddress ( asObject) }
178178 . map { _ in ( builder, Self . buildId ( for: builder) ) }
179179 }
180180 if let asObject = builder. destination {
181181 destination = asObject. rx. observeWeakly ( CLLocationCoordinate2D . self, " coordinate " )
182182 . compactMap { [ weak asObject] _ in asObject? . coordinate }
183183 . distinctUntilChanged ( isCloseEnough)
184- . flatMapLatest { [ weak asObject] _ in RouteBuilder . needAddress ( asObject, retryLimit : 3 , delay : 1 ) }
184+ . flatMapLatest { [ weak asObject] _ in RouteBuilder . needAddress ( asObject) }
185185 . map { _ in ( builder, Self . buildId ( for: builder) ) }
186186 }
187187 return Observable . merge ( origin, destination)
@@ -338,35 +338,28 @@ extension TKUIRoutingResultsViewModel.RouteBuilder {
338338 }
339339
340340 func reverseGeocodeLocations( ) -> Observable < ( origin: String ? , destination: String ? ) > {
341- let originObservable = Self . needAddress ( origin, retryLimit : 5 , delay : 5 )
342- let destinationObservable = Self . needAddress ( destination, retryLimit : 5 , delay : 5 )
341+ let originObservable = Self . needAddress ( origin)
342+ let destinationObservable = Self . needAddress ( destination)
343343 return Observable
344344 . combineLatest ( originObservable, destinationObservable) { ( origin: $0, destination: $1) }
345345 . distinctUntilChanged { $0. origin == $1. origin && $0. destination == $1. destination }
346346 }
347347
348- static func needAddress( _ location: TKNamedCoordinate ? , retryLimit : Int , delay : Int ) -> Observable < String ? > {
348+ static func needAddress( _ location: TKNamedCoordinate ? ) -> Observable < String ? > {
349349 if let from = location? . title, from != Loc . Location {
350350 return . just( from)
351351 } else if let location {
352- return Self . geocode ( location, retryLimit: retryLimit, delay: delay) . catchAndReturn ( nil )
352+ return Single . create {
353+ try await location. needsAddress ( includeName: true )
354+ return location. title
355+ }
356+ . asObservable ( )
357+ . catchAndReturn ( nil )
353358 } else {
354359 return . just( nil )
355360 }
356361 }
357362
358- private static func geocode( _ location: TKNamedCoordinate , retryLimit: Int , delay: Int ) -> Observable < String ? > {
359- return CLGeocoder ( ) . rx
360- . reverseGeocode ( namedCoordinate: location)
361- . asObservable ( )
362- . retry { errors in
363- return errors. enumerated ( ) . flatMap { ( index, error) -> Observable < Int > in
364- guard index < retryLimit else { throw error }
365- return Observable< Int> . timer( RxTimeInterval . seconds ( delay) , scheduler: MainScheduler . instance)
366- }
367- }
368- }
369-
370363 func generateRequest( ) -> TripRequest ? {
371364 guard let destination = destination, let time = time else { return nil }
372365
@@ -446,30 +439,4 @@ extension TKUIRoutingResultsViewModel.RouteBuilder: Equatable {
446439 }
447440}
448441
449- // MARK: -
450-
451- extension Reactive where Base: CLGeocoder {
452-
453- func reverseGeocode( namedCoordinate: TKNamedCoordinate ) -> Single < String ? > {
454- return Single . create { single in
455- let location = CLLocation ( latitude: namedCoordinate. coordinate. latitude, longitude: namedCoordinate. coordinate. longitude)
456-
457- let geocoder = CLGeocoder ( )
458- geocoder. reverseGeocodeLocation ( location) { ( placemarks, error) in
459- if let error {
460- single ( . failure( error) )
461- } else {
462- if let first = placemarks? . first {
463- // TODO: Shouldn't always overwrite the name, e.g., if it's from a favourite
464- namedCoordinate. assignPlacemark ( first, includeName: true )
465- }
466- single ( . success( placemarks? . first? . name) )
467- }
468- }
469-
470- return Disposables . create ( )
471- }
472- }
473-
474- }
475442
0 commit comments