Skip to content

Commit 543f2b6

Browse files
authored
Added Objective-C batch geocoding example
1 parent e05c00d commit 543f2b6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,30 @@ let task = geocoder.batchGeocode(options) { (placemarksByQuery, attributionsByQu
224224
}
225225
```
226226

227+
```objc
228+
// main.m
229+
MBForwardBatchGeocodeOptions *options = [[MBForwardBatchGeocodeOptions alloc] initWithQueries:@[@"skyline chili", @"gold star chili"]];
230+
options.focalLocation = locationManager.location;
231+
options.allowedScopes = MBPlacemarkScopePointOfInterest;
232+
233+
NSURLSessionDataTask *task = [geocoder batchGeocodeWithOptions:options
234+
completionHandler:^(NSArray<NSArray<MBGeocodedPlacemark *> *> * _Nullable placemarksByQuery,
235+
NSArray<NSString *> * _Nullable attributionsByQuery,
236+
NSError * _Nullable error) {
237+
if (!placemarksByQuery) {
238+
return;
239+
}
240+
241+
MBPlacemark *nearestSkyline = placemarksByQuery[0][0].location;
242+
CLLocationDistance distanceToSkyline = [nearestSkyline distanceFromLocation:locationManager.location];
243+
MBPlacemark *nearestGoldStar = placemarksByQuery[1][0].location;
244+
CLLocationDistance distanceToGoldStar = [nearestGoldStar distanceFromLocation:locationManager.location];
245+
246+
NSString *distance = [NSLengthFormatter stringFromMeters:MIN(distanceToSkyline, distanceToGoldStar)];
247+
NSLog(@"Found a chili parlor %@ away.", distance);
248+
}];
249+
```
250+
227251
Batch geocoding is available to Mapbox enterprise accounts. See the [Mapbox Geocoding](https://www.mapbox.com/geocoding/) website for more information.
228252
229253
## Tests

0 commit comments

Comments
 (0)