Skip to content

Commit 6c55349

Browse files
author
James Wolfe
committed
Fixed GetAddress integration
1 parent c1d7c36 commit 6c55349

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

.DS_Store

0 Bytes
Binary file not shown.

AtlasKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |spec|
22

33
spec.name = "AtlasKit"
4-
spec.version = "0.1.5"
4+
spec.version = "0.1.6"
55
spec.license = "MIT"
66
spec.summary = "A swift library for quickly integrating a location search in your app."
77
spec.homepage = "https://github.com/appoly/AtlasKit"

Sources/AtlasKit/AtlasKit.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ public class AtlasKit {
143143
"api-key": datasource.apiKey!
144144
]
145145

146-
let request = sessionManager.request(URL(string: "https://api.getaddress.io/find/\(postcode)")!,
146+
guard let searchTerm = postcode.trimmingCharacters(in: .whitespacesAndNewlines).addingPercentEncoding(withAllowedCharacters: .urlPathAllowed), let url = URL(string: "https://api.getaddress.io/find/\(searchTerm)") else {
147+
completion(nil, .generic)
148+
return
149+
}
150+
151+
let request = sessionManager.request(url,
147152
method: .get,
148153
parameters: parameters,
149154
encoding: URLEncoding.methodDependent,
@@ -174,7 +179,7 @@ public class AtlasKit {
174179
return
175180
}
176181

177-
completion(self?.formatResults(data, postcode: postcode.capitalized.removingAllWhitespaces, latitude: latitude, longitude: longitude), nil)
182+
completion(self?.formatResults(data, postcode: postcode.uppercased().removingAllWhitespaces, latitude: latitude, longitude: longitude), nil)
178183
}
179184
}
180185
}
@@ -184,7 +189,7 @@ public class AtlasKit {
184189
// MARK: - Utilities
185190

186191
private func formatResults(_ items: [MKPlacemark]) -> [AtlasKitPlace] {
187-
return items.map({ AtlasKitPlace(streetAddress: $0.postalAddress!.street, city: $0.postalAddress!.city, postcode: $0.postalAddress!.postalCode, state: $0.postalAddress!.state, country: $0.postalAddress!.country, location: $0.coordinate) })
192+
return items.map({ AtlasKitPlace(streetAddress: $0.postalAddress!.street, city: $0.postalAddress!.city, postcode: $0.postalAddress!.postalCode, state: $0.postalAddress!.state, country: $0.postalAddress!.country, location: $0.coordinate) }).sorted(by: { $0.formattedAddress.localizedStandardCompare($1.formattedAddress) == .orderedAscending })
188193
}
189194

190195

@@ -195,17 +200,17 @@ public class AtlasKit {
195200
let address2 = components.indices.contains(1) ? components[1] : ""
196201
let address3 = components.indices.contains(2) ? components[2] : ""
197202
let address4 = components.indices.contains(3) ? components[3] : ""
198-
let address = ([address1, address2, address3, address4].filter({ !$0.isEmpty }).map({ String($0) }).joined(separator: ", "))
203+
let address = ([address1, address2, address3, address4].filter({ !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }).map({ String($0) }).joined(separator: ", "))
199204
let city = components.indices.contains(5) ? components[5] : ""
200205
let county = components.indices.contains(6) ? components[6] : ""
201206

202207
return AtlasKitPlace(streetAddress: address, city: String(city), postcode: postcode, state: String(county), country: "United Kingdom", location: CLLocationCoordinate2D(latitude: latitude, longitude: longitude))
203-
})
208+
}).sorted(by: { $0.formattedAddress.localizedStandardCompare($1.formattedAddress) == .orderedAscending })
204209
}
205210

206211

207212
private func formatResults(_ items: [[String: Any]]) -> [AtlasKitPlace] {
208-
return items.map { item -> AtlasKitPlace? in
213+
let addresses = items.map { item -> AtlasKitPlace? in
209214

210215
guard let address = item["formatted_address"] as? String,
211216
let geometry = item["geometry"] as? [String: Any],
@@ -217,6 +222,8 @@ public class AtlasKit {
217222

218223
return AtlasKitPlace(streetAddress: GoogleHelper.extractStreetAddress(from: address), city: GoogleHelper.extractCity(from: address), postcode: GoogleHelper.extractPostcode(from: address), state: GoogleHelper.extractState(from: address), country: GoogleHelper.extractCountry(from: address), location: CLLocationCoordinate2D(latitude: latitude, longitude: longitude))
219224
}.filter({ $0 != nil && ($0!.formattedAddress.first) != nil }) as! [AtlasKitPlace]
225+
226+
return addresses.sorted(by: { $0.formattedAddress.localizedStandardCompare($1.formattedAddress) == .orderedAscending })
220227
}
221228

222229

@@ -235,3 +242,4 @@ extension String {
235242
}
236243

237244
}
245+

0 commit comments

Comments
 (0)