-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathCLGeocoder+Promise.swift
81 lines (70 loc) · 2.95 KB
/
CLGeocoder+Promise.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import CoreLocation.CLGeocoder
#if !PMKCocoaPods
import PromiseKit
#endif
#if os(iOS) || os(watchOS) || os(OSX)
import class Contacts.CNPostalAddress
#endif
/**
To import the `CLGeocoder` category:
use_frameworks!
pod "PromiseKit/CoreLocation"
And then in your sources:
import PromiseKit
*/
extension CLGeocoder {
/// Submits a reverse-geocoding request for the specified location.
public func reverseGeocode(location: CLLocation) -> Promise<[CLPlacemark]> {
return Promise { seal in
reverseGeocodeLocation(location, completionHandler: seal.resolve)
}
}
/// Submits a forward-geocoding request using the specified address dictionary.
@available(iOS, deprecated: 11.0)
public func geocode(_ addressDictionary: [String: String]) -> Promise<[CLPlacemark]> {
return Promise { seal in
geocodeAddressDictionary(addressDictionary, completionHandler: seal.resolve)
}
}
/// Submits a forward-geocoding request using the specified address string.
public func geocode(_ addressString: String) -> Promise<[CLPlacemark]> {
return Promise { seal in
geocodeAddressString(addressString, completionHandler: seal.resolve)
}
}
/// Submits a forward-geocoding request using the specified address string within the specified region.
public func geocode(_ addressString: String, region: CLRegion?) -> Promise<[CLPlacemark]> {
return Promise { seal in
geocodeAddressString(addressString, in: region, completionHandler: seal.resolve)
}
}
#if !os(tvOS) && swift(>=3.2)
/// Submits a forward-geocoding request using the specified postal address.
@available(iOS 11.0, OSX 10.13, watchOS 4.0, *)
public func geocodePostalAddress(_ postalAddress: CNPostalAddress) -> Promise<[CLPlacemark]> {
return Promise { seal in
geocodePostalAddress(postalAddress, completionHandler: seal.resolve)
}
}
/// Submits a forward-geocoding requesting using the specified locale and postal address
@available(iOS 11.0, OSX 10.13, watchOS 4.0, *)
public func geocodePostalAddress(_ postalAddress: CNPostalAddress, preferredLocale locale: Locale?) -> Promise<[CLPlacemark]> {
return Promise { seal in
geocodePostalAddress(postalAddress, preferredLocale: locale, completionHandler: seal.resolve)
}
}
/// Submits a reverse-geocoding request for the specified location and a preferred locale.
@available(iOS 11.0, OSX 10.13, watchOS 4.0, *)
public func reverseGeocode(location: CLLocation, preferredLocale locale: Locale?) -> Promise<[CLPlacemark]> {
return Promise { seal in
reverseGeocodeLocation(location, preferredLocale: locale, completionHandler: seal.resolve)
}
}
#endif
}
// TODO still not possible in Swift 3.2
//extension CLError: CancellableError {
// public var isCancelled: Bool {
// return self == .geocodeCanceled
// }
//}