Skip to content

Commit af6119f

Browse files
authored
add support for configurable limit count per server API (#85)
1 parent 1027dda commit af6119f

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

MapboxGeocoder/MBGeocodeOptions.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class GeocodeOptions: NSObject {
2626
public var allowedISOCountryCodes: [String]?
2727

2828
/**
29-
A loation to use as a hint when looking up the specified address.
29+
A location to use as a hint when looking up the specified address.
3030

3131
This property prioritizes results that are close to a specific location, which is typically the user’s current location. If the value of this property is `nil` – which it is by default – no specific location is prioritized.
3232
*/
@@ -46,6 +46,11 @@ public class GeocodeOptions: NSObject {
4646
*/
4747
public var allowedRegion: RectangularRegion?
4848

49+
/**
50+
Limit the number of results returned. The default is `5` for forward geocoding and `1` for reverse geocoding.
51+
*/
52+
public var maximumResultCount: UInt
53+
4954
// MARK: Specifying the Output Format
5055

5156
/**
@@ -59,7 +64,10 @@ public class GeocodeOptions: NSObject {
5964
*/
6065
public var locale: NSLocale?
6166

62-
private override init() {}
67+
private override init() {
68+
self.maximumResultCount = 0
69+
super.init()
70+
}
6371

6472
/**
6573
An array of geocoding query strings to include in the request URL.
@@ -87,6 +95,9 @@ public class GeocodeOptions: NSObject {
8795
if let allowedRegion = allowedRegion {
8896
params.append(NSURLQueryItem(name: "bbox", value: String(allowedRegion)))
8997
}
98+
if maximumResultCount > 0 {
99+
params.append(NSURLQueryItem(name: "limit", value: String(maximumResultCount)))
100+
}
90101
if let languageCode = locale?.objectForKey(NSLocaleLanguageCode) as? String {
91102
params.append(NSURLQueryItem(name: "language", value: languageCode))
92103
}
@@ -105,10 +116,11 @@ public class ForwardGeocodeOptions: GeocodeOptions {
105116
If true, a resulting placemark’s name may contain a word that begins with the query string. If false, the query string must match a whole word or phrase in the placemark’s name. The default value of this property is true, which is best suited for continuous search fields.
106117
*/
107118
public var autocompletesQuery = true
108-
119+
109120
private init(queries: [String]) {
110121
super.init()
111122
self.queries = queries
123+
self.maximumResultCount = 5
112124
}
113125

114126
/**
@@ -151,10 +163,11 @@ public class ReverseGeocodeOptions: GeocodeOptions {
151163
An array of coordinates to search for.
152164
*/
153165
public var coordinates: [CLLocationCoordinate2D]
154-
166+
155167
private init(coordinates: [CLLocationCoordinate2D]) {
156168
self.coordinates = coordinates
157169
super.init()
170+
self.maximumResultCount = 1
158171
queries = coordinates.map { String(format: "%.5f,%.5f", $0.longitude, $0.latitude) }
159172
}
160173

Podfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
PODS:
2-
- Mapbox-iOS-SDK (3.3.4)
3-
- OHHTTPStubs/Core (5.2.1)
4-
- OHHTTPStubs/Swift (5.2.1):
2+
- Mapbox-iOS-SDK (3.3.6)
3+
- OHHTTPStubs/Core (5.2.2)
4+
- OHHTTPStubs/Swift (5.2.2):
55
- OHHTTPStubs/Core
66

77
DEPENDENCIES:
88
- Mapbox-iOS-SDK (~> 3.3)
99
- OHHTTPStubs/Swift (~> 5.0)
1010

1111
SPEC CHECKSUMS:
12-
Mapbox-iOS-SDK: b22da0d9703fcfb0a8b592b6a7f6a21264fe44b0
13-
OHHTTPStubs: 3a42f25c00563b71355ac73112ba2324e9e6cef4
12+
Mapbox-iOS-SDK: 1651ab31beec917b60ccbb8f737d0435ec80eeb3
13+
OHHTTPStubs: 34d9d0994e64fcf8552dbfade5ce82ada913ee31
1414

1515
PODFILE CHECKSUM: 0d327e0fe430b4211f61e91065c69151ac64aef7
1616

17-
COCOAPODS: 1.1.0.rc.2
17+
COCOAPODS: 1.1.1

0 commit comments

Comments
 (0)