Reverse geocoding

This commit is contained in:
Selim Mustafaev 2020-08-24 00:37:48 +03:00
parent c39971637d
commit 9bd3426f14
7 changed files with 35 additions and 18 deletions

View File

@ -17,7 +17,7 @@
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
uuid = "CF01B44D-372B-4C78-A197-7FDEC607CE0E"
shouldBeEnabled = "Yes"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
scope = "1"
@ -28,7 +28,7 @@
BreakpointExtensionID = "Xcode.Breakpoint.SymbolicBreakpoint">
<BreakpointContent
uuid = "B15A9E9C-A0CD-4FC9-8E24-DD93FB1B677F"
shouldBeEnabled = "Yes"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "UITableViewAlertForLayoutOutsideViewHierarchy"

View File

@ -23,7 +23,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let config = Realm.Configuration(
schemaVersion: 13,
schemaVersion: 14,
migrationBlock: { migration, oldSchemaVersion in
if oldSchemaVersion <= 3 {
var numbers: [String] = []

View File

@ -147,6 +147,7 @@ class CheckController: UIViewController, MaskedTextFieldDelegateListener, UITabl
let eventSingle = event == nil ? self.getEvent() : Single.just(event!)
eventSingle
.flatMap { event in event.updateAddress().map{ event }.catchErrorJustReturn(event) }
.flatMap { Api.add(event: $0, to: vehicle.number) }
.subscribe(onSuccess: self.save(vehicle:), onError: { print("Error adding event: \($0)") })
.disposed(by: self.bag)

View File

@ -28,6 +28,7 @@ enum ReportGeneralSection: Int, CaseIterable, CustomStringConvertible {
case wheelPosition = 3
case japanese = 4
case owners = 5
case events = 6
var description: String {
switch self {
@ -37,6 +38,7 @@ enum ReportGeneralSection: Int, CaseIterable, CustomStringConvertible {
case .wheelPosition: return "Steering wheel position"
case .japanese: return "Japanese"
case .owners: return "Owners (from PTS)"
case .events: return "Events"
}
}
}
@ -172,6 +174,8 @@ class ReportController: UIViewController, UICollectionViewDataSource, UICollecti
case .owners:
cell?.configure(param: generalSection.description, value: String(vehicle.ownershipPeriods.count))
break
case .events:
cell?.configure(param: generalSection.description, value: String(vehicle.events.count))
}
}
return cell ?? UICollectionViewCell()

View File

@ -1,5 +1,6 @@
import Foundation
import RealmSwift
import RxSwift
class VehicleEvent: Object, Codable {
@objc dynamic var date: TimeInterval = Date().timeIntervalSince1970
@ -20,7 +21,9 @@ class VehicleEvent: Object, Codable {
super.init()
}
override class func ignoredProperties() -> [String] {
return ["address"]
func updateAddress() -> Single<Void> {
return LocationManager
.getAddressForLocation(latitude: self.latitude, longitude: self.longitude)
.map { self.address = $0 }
}
}

View File

@ -3,8 +3,8 @@ import Foundation
enum Constants {
static var baseUrl: String {
#if DEBUG
//return "http://192.168.1.67:3000/"
return "https://vps.aliencat.pro:8443/"
return "http://192.168.1.67:3000/"
//return "https://vps.aliencat.pro:8443/"
#else
return "https://vps.aliencat.pro:8443/"
#endif

View File

@ -19,17 +19,6 @@ class RxLocationManagerDelegateProxy: DelegateProxy<CLLocationManager, CLLocatio
print("deinit")
}
// func generateAuthObservable() -> Observable<CLAuthorizationStatus> {
// self.authSubject = PublishSubject<CLAuthorizationStatus>()
// return self.authSubject
// }
//
// func generateLocationObservable() -> Observable<CLLocation> {
// print("generateLocationObservable")
// self.locationSubject = PublishSubject<CLLocation>()
// return self.locationSubject
// }
// MARK: - DelegateProxyType
static func registerKnownImplementations() {
@ -126,4 +115,24 @@ class LocationManager {
self.manager.stopUpdatingLocation()
})
}
static func getAddressForLocation(latitude: Double, longitude: Double) -> Single<String> {
return Single.create { observer in
let geocoder = CLGeocoder()
let location = CLLocation(latitude: latitude, longitude: longitude)
geocoder.reverseGeocodeLocation(location) { placemarks, error in
if let error = error {
observer(.error(error))
} else if let placemark = placemarks?.first, let name = placemark.name {
observer(.success(name))
} else {
observer(.error(NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Reverse geolocation error"])))
}
}
return Disposables.create {
geocoder.cancelGeocode()
}
}
}
}