Skip to content

Commit d503e05

Browse files
committed
Refined geocoding methods for Objective-C
1 parent b392a08 commit d503e05

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

Geocoder Example/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ - (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
5656
[self.geocodingDataTask cancel];
5757
MBReverseGeocodeOptions *options = [[MBReverseGeocodeOptions alloc] initWithCoordinate:self.mapView.centerCoordinate];
5858
options.allowedScopes = MBPlacemarkScopeAll;
59-
[self.geocoder geocode:options completionHandler:^(NSArray<MBGeocodedPlacemark *> * _Nullable placemarks, NSString * _Nullable attribution, NSError * _Nullable error) {
59+
[self.geocoder geocodeWithOptions:options completionHandler:^(NSArray<MBGeocodedPlacemark *> * _Nullable placemarks, NSString * _Nullable attribution, NSError * _Nullable error) {
6060
if (error) {
6161
NSLog(@"%@", error);
6262
} else if (placemarks.count > 0) {

MapboxGeocoder/MBGeocoder.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ open class Geocoder: NSObject {
170170
- parameter completionHandler: The closure (block) to call with the resulting placemarks. This closure is executed on the application’s main thread.
171171
- returns: The data task used to perform the HTTP request. If, while waiting for the completion handler to execute, you no longer want the resulting placemarks, cancel this task.
172172
*/
173+
@objc(geocodeWithOptions:completionHandler:)
173174
open func geocode(_ options: GeocodeOptions, completionHandler: @escaping CompletionHandler) -> URLSessionDataTask {
174175
let url = urlForGeocoding(options)
175176
let task = dataTaskWithURL(url, completionHandler: { (json) in

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ options.allowedISOCountryCodes = @[@"CA"];
119119
options.focalLocation = [[CLLocation alloc] initWithLatitude:45.3 longitude:-66.1];
120120
options.allowedScopes = MBPlacemarkScopeAddress | MBPlacemarkScopePointOfInterest;
121121

122-
NSURLSessionDataTask *task = [geocoder geocode:options
123-
completionHandler:^(NSArray<MBGeocodedPlacemark *> * _Nullable placemarks,
124-
NSString * _Nullable attribution,
125-
NSError * _Nullable error) {
122+
NSURLSessionDataTask *task = [geocoder geocodeWithOptions:options
123+
completionHandler:^(NSArray<MBGeocodedPlacemark *> * _Nullable placemarks,
124+
NSString * _Nullable attribution,
125+
NSError * _Nullable error) {
126126
MBPlacemark *placemark = placemarks[0];
127127
NSLog(@"%@", placemark.name);
128128
// 200 Queen St
@@ -175,10 +175,10 @@ let task = geocoder.geocode(options) { (placemarks, attribution, error) in
175175
MBReverseGeocodeOptions *options = [[MBReverseGeocodeOptions alloc] initWithCoordinate: CLLocationCoordinate2DMake(40.733, -73.989)];
176176
// Or perhaps: [[MBReverseGeocodeOptions alloc] initWithLocation:locationManager.location]
177177

178-
NSURLSessionDataTask *task = [geocoder geocode:options
179-
completionHandler:^(NSArray<MBGeocodedPlacemark *> * _Nullable placemarks,
180-
NSString * _Nullable attribution,
181-
NSError * _Nullable error) {
178+
NSURLSessionDataTask *task = [geocoder geocodeWithOptions:options
179+
completionHandler:^(NSArray<MBGeocodedPlacemark *> * _Nullable placemarks,
180+
NSString * _Nullable attribution,
181+
NSError * _Nullable error) {
182182
MBPlacemark *placemark = placemarks[0];
183183
NSLog(@"%@", placemark.imageName);
184184
// telephone

0 commit comments

Comments
 (0)