Skip to content

Commit 34b1af7

Browse files
committed
Added batch geocoding example
1 parent 6257e0c commit 34b1af7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,41 @@ NSURLSessionDataTask *task = [geocoder geocode:options
197197
198198
With _batch geocoding_, you can perform up to 50 distinct forward or reverse geocoding requests simultaneously and store the results in a private database. Create a ForwardBatchGeocodingOptions or ReverseBatchGeocodingOptions object in Swift, or an MBForwardBatchGeocodingOptions or MBReverseBatchGeocodingOptions object in Objective-C, and pass it into the `Geocoder.batchGeocode(_:completionHandler:)` method.
199199
200+
```swift
201+
// main.swift
202+
let options = ForwardBatchGeocodeOptions(queries: ["skyline chili", "gold star chili"])
203+
options.focalLocation = locationManager.location
204+
options.allowedScopes = .pointOfInterest
205+
206+
let task = geocoder.batchGeocode(options) { (placemarksByQuery, attributionsByQuery, error) in
207+
let nearestSkyline = placemarksByQuery[0][0].location
208+
let distanceToSkyline = nearestSkyline.distance(from: locationManager.location)
209+
let nearestGoldStar = placemarksByQuery[1][0].location
210+
let distanceToGoldStar = nearestGoldStar.distance(from: locationManager.location)
211+
212+
let distance = LengthFormatter().string(fromMeters: min(distanceToSkyline, distanceToGoldStar))
213+
print("Found a chili parlor \(distance) away.")
214+
}
215+
```
216+
217+
```objc
218+
// main.m
219+
MBForwardBatchGeocodeOptions *options = [[MBForwardBatchGeocodeOptions alloc] initWithQueries:@[@"skyline chili", @"gold star chili"]];
220+
options.focalLocation = locationManager.location;
221+
options.allowedScopes = MBPlacemarkScopePointOfInterest;
222+
223+
NSURLSessionDataTask *task = [geocoder batchGeocode:options completionHandler:^(NSArray<NSArray<MBGeocodedPlacemark *> *> * _Nullable placemarksByQuery, NSArray<NSString *> * _Nullable attributionsByQuery, NSError * _Nullable error) {
224+
MBPlacemark *nearestSkyline = placemarksByQuery[0][0].location;
225+
CLLocationDistance distanceToSkyline = [nearestSkyline distanceFromLocation:locationManager.location];
226+
MBPlacemark *nearestGoldStar = placemarksByQuery[1][0].location;
227+
CLLocationDistance distanceToGoldStar = [nearestGoldStar distanceFromLocation:locationManager.location];
228+
229+
NSLengthFormatter *formatter = [[NSLengthFormatter alloc] init];
230+
NSString *distance = [formatter stringFromMeters:MIN(distanceToSkyline, distanceToGoldStar)];
231+
NSLog("Found a chili parlor %@ away.", distance);
232+
}];
233+
```
234+
200235
Batch geocoding is available to Mapbox enterprise accounts. See the [Mapbox Geocoding](https://www.mapbox.com/geocoding/) website for more information.
201236
202237
## Tests

0 commit comments

Comments
 (0)