@@ -10,7 +10,7 @@ import Foundation
10
10
11
11
import AWSLocation
12
12
13
- extension AWSLocationGeoPlugin {
13
+ public extension AWSLocationGeoPlugin {
14
14
15
15
// MARK: - Search
16
16
@@ -30,8 +30,10 @@ extension AWSLocationGeoPlugin {
30
30
/// `Geo.Error.networkError` if request failed or network unavailable
31
31
/// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin
32
32
/// `Geo.Error.unknown` if error is unknown
33
- public func search( for text: String ,
34
- options: Geo . SearchForTextOptions ? = nil ) async throws -> [ Geo . Place ] {
33
+ func search(
34
+ for text: String ,
35
+ options: Geo . SearchForTextOptions ? = nil
36
+ ) async throws -> [ Geo . Place ] {
35
37
36
38
var request = SearchPlaceIndexForTextInput ( )
37
39
@@ -41,21 +43,26 @@ extension AWSLocationGeoPlugin {
41
43
guard request. indexName != nil else {
42
44
throw Geo . Error. invalidConfiguration (
43
45
GeoPluginErrorConstants . missingDefaultSearchIndex. errorDescription,
44
- GeoPluginErrorConstants . missingDefaultSearchIndex. recoverySuggestion)
46
+ GeoPluginErrorConstants . missingDefaultSearchIndex. recoverySuggestion
47
+ )
45
48
}
46
49
47
50
request. text = text
48
51
49
52
if let area = options? . area {
50
53
switch area {
51
54
case . near( let coordinates) :
52
- request. biasPosition = [ coordinates. longitude,
53
- coordinates. latitude]
55
+ request. biasPosition = [
56
+ coordinates. longitude,
57
+ coordinates. latitude
58
+ ]
54
59
case . within( let boundingBox) :
55
- request. filterBBox = [ boundingBox. southwest. longitude,
56
- boundingBox. southwest. latitude,
57
- boundingBox. northeast. longitude,
58
- boundingBox. northeast. latitude]
60
+ request. filterBBox = [
61
+ boundingBox. southwest. longitude,
62
+ boundingBox. southwest. latitude,
63
+ boundingBox. northeast. longitude,
64
+ boundingBox. northeast. latitude
65
+ ]
59
66
}
60
67
}
61
68
@@ -73,9 +80,7 @@ extension AWSLocationGeoPlugin {
73
80
let response = try await locationService. searchPlaceIndex ( forText: request)
74
81
var results = [ LocationClientTypes . Place] ( )
75
82
if let responseResults = response. results {
76
- results = responseResults. compactMap {
77
- $0. place
78
- }
83
+ results = responseResults. compactMap ( \. place)
79
84
}
80
85
81
86
let places : [ Geo . Place ] = results. compactMap {
@@ -85,16 +90,18 @@ extension AWSLocationGeoPlugin {
85
90
return nil
86
91
}
87
92
88
- return Geo . Place ( coordinates: Geo . Coordinates ( latitude: lat, longitude: long) ,
89
- label: $0. label,
90
- addressNumber: $0. addressNumber,
91
- street: $0. street,
92
- municipality: $0. municipality,
93
- neighborhood: $0. neighborhood,
94
- region: $0. region,
95
- subRegion: $0. subRegion,
96
- postalCode: $0. postalCode,
97
- country: $0. country)
93
+ return Geo . Place (
94
+ coordinates: Geo . Coordinates ( latitude: lat, longitude: long) ,
95
+ label: $0. label,
96
+ addressNumber: $0. addressNumber,
97
+ street: $0. street,
98
+ municipality: $0. municipality,
99
+ neighborhood: $0. neighborhood,
100
+ region: $0. region,
101
+ subRegion: $0. subRegion,
102
+ postalCode: $0. postalCode,
103
+ country: $0. country
104
+ )
98
105
}
99
106
return places
100
107
} catch let error as GeoErrorConvertible {
@@ -123,8 +130,10 @@ extension AWSLocationGeoPlugin {
123
130
/// `Geo.Error.networkError` if request failed or network unavailable
124
131
/// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin
125
132
/// `Geo.Error.unknown` if error is unknown
126
- public func search( for coordinates: Geo . Coordinates ,
127
- options: Geo . SearchForCoordinatesOptions ? = nil ) async throws -> [ Geo . Place ] {
133
+ func search(
134
+ for coordinates: Geo . Coordinates ,
135
+ options: Geo . SearchForCoordinatesOptions ? = nil
136
+ ) async throws -> [ Geo . Place ] {
128
137
129
138
var request = SearchPlaceIndexForPositionInput ( )
130
139
@@ -134,11 +143,14 @@ extension AWSLocationGeoPlugin {
134
143
guard request. indexName != nil else {
135
144
throw Geo . Error. invalidConfiguration (
136
145
GeoPluginErrorConstants . missingDefaultSearchIndex. errorDescription,
137
- GeoPluginErrorConstants . missingDefaultSearchIndex. recoverySuggestion)
146
+ GeoPluginErrorConstants . missingDefaultSearchIndex. recoverySuggestion
147
+ )
138
148
}
139
149
140
- request. position = [ coordinates. longitude,
141
- coordinates. latitude]
150
+ request. position = [
151
+ coordinates. longitude,
152
+ coordinates. latitude
153
+ ]
142
154
143
155
if let maxResults = options? . maxResults {
144
156
request. maxResults = maxResults as Int
@@ -148,9 +160,7 @@ extension AWSLocationGeoPlugin {
148
160
let response = try await locationService. searchPlaceIndex ( forPosition: request)
149
161
var results = [ LocationClientTypes . Place] ( )
150
162
if let responseResults = response. results {
151
- results = responseResults. compactMap {
152
- $0. place
153
- }
163
+ results = responseResults. compactMap ( \. place)
154
164
}
155
165
156
166
let places : [ Geo . Place ] = results. compactMap {
@@ -160,16 +170,18 @@ extension AWSLocationGeoPlugin {
160
170
return nil
161
171
}
162
172
163
- return Geo . Place ( coordinates: Geo . Coordinates ( latitude: lat, longitude: long) ,
164
- label: $0. label,
165
- addressNumber: $0. addressNumber,
166
- street: $0. street,
167
- municipality: $0. municipality,
168
- neighborhood: $0. neighborhood,
169
- region: $0. region,
170
- subRegion: $0. subRegion,
171
- postalCode: $0. postalCode,
172
- country: $0. country)
173
+ return Geo . Place (
174
+ coordinates: Geo . Coordinates ( latitude: lat, longitude: long) ,
175
+ label: $0. label,
176
+ addressNumber: $0. addressNumber,
177
+ street: $0. street,
178
+ municipality: $0. municipality,
179
+ neighborhood: $0. neighborhood,
180
+ region: $0. region,
181
+ subRegion: $0. subRegion,
182
+ postalCode: $0. postalCode,
183
+ country: $0. country
184
+ )
173
185
}
174
186
return places
175
187
} catch let error as GeoErrorConvertible {
@@ -194,12 +206,13 @@ extension AWSLocationGeoPlugin {
194
206
/// `Geo.Error.networkError` if request failed or network unavailable
195
207
/// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin
196
208
/// `Geo.Error.unknown` if error is unknown
197
- public func availableMaps( ) async throws -> [ Geo . MapStyle ] {
209
+ func availableMaps( ) async throws -> [ Geo . MapStyle ] {
198
210
let mapStyles = Array ( pluginConfig. maps. values)
199
211
guard !mapStyles. isEmpty else {
200
212
throw Geo . Error. invalidConfiguration (
201
213
GeoPluginErrorConstants . missingMaps. errorDescription,
202
- GeoPluginErrorConstants . missingMaps. recoverySuggestion)
214
+ GeoPluginErrorConstants . missingMaps. recoverySuggestion
215
+ )
203
216
}
204
217
return mapStyles
205
218
}
@@ -213,11 +226,12 @@ extension AWSLocationGeoPlugin {
213
226
/// `Geo.Error.networkError` if request failed or network unavailable
214
227
/// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin
215
228
/// `Geo.Error.unknown` if error is unknown
216
- public func defaultMap( ) async throws -> Geo . MapStyle {
229
+ func defaultMap( ) async throws -> Geo . MapStyle {
217
230
guard let mapName = pluginConfig. defaultMap, let mapStyle = pluginConfig. maps [ mapName] else {
218
231
throw Geo . Error. invalidConfiguration (
219
232
GeoPluginErrorConstants . missingDefaultMap. errorDescription,
220
- GeoPluginErrorConstants . missingDefaultMap. recoverySuggestion)
233
+ GeoPluginErrorConstants . missingDefaultMap. recoverySuggestion
234
+ )
221
235
}
222
236
return mapStyle
223
237
}
0 commit comments