Skip to content

Commit 6759a16

Browse files
committed
Merge pull request #43 from mapbox/1ec5-public-placemark
Took GeocodedPlacemark, QualifyingPlacemark public
2 parents 38dc075 + a137fb0 commit 6759a16

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

Geocoder Example/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
5454
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
5555
[self.geocodingDataTask cancel];
5656
MBReverseGeocodeOptions *options = [[MBReverseGeocodeOptions alloc] initWithCoordinate:self.mapView.centerCoordinate];
57-
[self.geocoder geocodeWithOptions:options completionHandler:^(NSArray<MBPlacemark *> * _Nullable placemarks, NSString * _Nullable attribution, NSError * _Nullable error) {
57+
[self.geocoder geocodeWithOptions:options completionHandler:^(NSArray<MBGeocodedPlacemark *> * _Nullable placemarks, NSString * _Nullable attribution, NSError * _Nullable error) {
5858
if (error) {
5959
NSLog(@"%@", error);
6060
} else if (placemarks.count > 0) {

MapboxGeocoder/MBGeocoder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class Geocoder: NSObject {
5353
- parameter attribution: A legal notice indicating the source, copyright status, and terms of use of the placemark data.
5454
- parameter error: The error that occurred, or `nil` if the placemarks were obtained successfully.
5555
*/
56-
public typealias CompletionHandler = (placemarks: [Placemark]?, attribution: String?, error: NSError?) -> Void
56+
public typealias CompletionHandler = (placemarks: [GeocodedPlacemark]?, attribution: String?, error: NSError?) -> Void
5757

5858
/**
5959
A closure (block) to be called when a geocoding request is complete.
@@ -64,7 +64,7 @@ public class Geocoder: NSObject {
6464
- parameter attributionsByQuery: An array of legal notices indicating the sources, copyright statuses, and terms of use of the placemark data for each query.
6565
- parameter error: The error that occurred, or `nil` if the placemarks were obtained successfully.
6666
*/
67-
public typealias BatchCompletionHandler = (placemarksByQuery: [[Placemark]]?, attributionsByQuery: [String]?, error: NSError?) -> Void
67+
public typealias BatchCompletionHandler = (placemarksByQuery: [[GeocodedPlacemark]]?, attributionsByQuery: [String]?, error: NSError?) -> Void
6868

6969
/**
7070
The shared geocoder object.
@@ -153,7 +153,7 @@ public class Geocoder: NSObject {
153153
let url = URLForGeocoding(options: options)
154154
let task = dataTaskWithURL(url, completionHandler: { (json) in
155155
let featureCollections = json as! [JSONDictionary]
156-
let placemarksByQuery = featureCollections.map { (featureCollection) -> [Placemark] in
156+
let placemarksByQuery = featureCollections.map { (featureCollection) -> [GeocodedPlacemark] in
157157
assert(featureCollection["type"] as? String == "FeatureCollection")
158158
let features = featureCollection["features"] as! [JSONDictionary]
159159
return features.flatMap { GeocodedPlacemark(featureJSON: $0) }

MapboxGeocoder/MBPlacemark.swift

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ public class Placemark: NSObject, NSCopying, NSSecureCoding {
338338
/**
339339
A concrete subclass of `Placemark` to represent results of geocoding requests.
340340
*/
341-
internal class GeocodedPlacemark: Placemark {
341+
@objc(MBGeocodedPlacemark)
342+
public class GeocodedPlacemark: Placemark {
342343
private let propertiesJSON: JSONDictionary
343344

344345
override init(featureJSON: JSONDictionary) {
@@ -352,24 +353,24 @@ internal class GeocodedPlacemark: Placemark {
352353
superiorPlacemarks = contextJSON?.map { QualifyingPlacemark(featureJSON: $0) }
353354
}
354355

355-
override func copyWithZone(zone: NSZone) -> AnyObject {
356+
public override func copyWithZone(zone: NSZone) -> AnyObject {
356357
return GeocodedPlacemark(featureJSON: featureJSON)
357358
}
358359

359-
override var debugDescription: String {
360+
public override var debugDescription: String {
360361
return qualifiedName
361362
}
362363

363-
override var qualifiedName: String! {
364+
public override var qualifiedName: String! {
364365
return featureJSON["place_name"] as! String
365366
}
366367

367-
override var location: CLLocation {
368+
public override var location: CLLocation {
368369
let centerCoordinate = CLLocationCoordinate2D(geoJSON: featureJSON["center"] as! [Double])
369370
return CLLocation(coordinate: centerCoordinate)
370371
}
371372

372-
override var region: RectangularRegion? {
373+
public override var region: CLRegion? {
373374
guard let boundingBox = featureJSON["bbox"] as? [Double] else {
374375
return nil
375376
}
@@ -380,7 +381,7 @@ internal class GeocodedPlacemark: Placemark {
380381
return RectangularRegion(southWest: southWest, northEast: northEast)
381382
}
382383

383-
override var name: String {
384+
public override var name: String {
384385
let text = super.name
385386

386387
// For address features, `text` is just the street name. Look through the fully-qualified address to determine whether to put the house number before or after the street name.
@@ -397,19 +398,19 @@ internal class GeocodedPlacemark: Placemark {
397398
}
398399
}
399400

400-
override var code: String? {
401+
public override var code: String? {
401402
return (propertiesJSON["short_code"] as? String)?.uppercaseString
402403
}
403404

404-
override var wikidataItemIdentifier: String? {
405+
public override var wikidataItemIdentifier: String? {
405406
let item = propertiesJSON["wikidata"] as? String
406407
if let item = item {
407408
assert(item.hasPrefix("Q"))
408409
}
409410
return item
410411
}
411412

412-
override var genres: [String]? {
413+
public override var genres: [String]? {
413414
let categoryList = propertiesJSON["category"] as? String
414415
return categoryList?.componentsSeparatedByString(", ")
415416
}
@@ -420,7 +421,7 @@ internal class GeocodedPlacemark: Placemark {
420421
}
421422

422423
@available(iOS 9.0, *)
423-
override var postalAddress: CNPostalAddress? {
424+
public override var postalAddress: CNPostalAddress? {
424425
let postalAddress = CNMutablePostalAddress()
425426

426427
if scope == .Address {
@@ -448,7 +449,7 @@ internal class GeocodedPlacemark: Placemark {
448449
return postalAddress
449450
}
450451

451-
override var addressDictionary: [NSObject: AnyObject]? {
452+
public override var addressDictionary: [NSObject: AnyObject]? {
452453
var addressDictionary: [String: AnyObject] = [:]
453454
if scope == .Address {
454455
addressDictionary[MBPostalAddressStreetKey] = name
@@ -473,24 +474,25 @@ internal class GeocodedPlacemark: Placemark {
473474
/**
474475
The phone number to contact a business at this location.
475476
*/
476-
override var phoneNumber: String? {
477+
public override var phoneNumber: String? {
477478
return propertiesJSON["tel"] as? String
478479
}
479480
}
480481

481482
/**
482483
A concrete subclass of `Placemark` to represent entries in a `GeocodedPlacemark` object’s `superiorPlacemarks` property. These entries are like top-level geocoding results, except that they lack location information and are flatter, with properties directly at the top level.
483484
*/
484-
private class QualifyingPlacemark: Placemark {
485-
override func copyWithZone(zone: NSZone) -> AnyObject {
485+
@objc(MBQualifyingPlacemark)
486+
public class QualifyingPlacemark: Placemark {
487+
public override func copyWithZone(zone: NSZone) -> AnyObject {
486488
return QualifyingPlacemark(featureJSON: featureJSON)
487489
}
488490

489-
override var code: String? {
491+
public override var code: String? {
490492
return (featureJSON["short_code"] as? String)?.uppercaseString
491493
}
492494

493-
override var wikidataItemIdentifier: String? {
495+
public override var wikidataItemIdentifier: String? {
494496
let item = featureJSON["wikidata"] as? String
495497
if let item = item {
496498
assert(item.hasPrefix("Q"))

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ options.focalLocation = [[CLLocation alloc] initWithLatitude:45.3 longitude:-66.
9898
options.allowedScopes = MBPlacemarkScopeAddress | MBPlacemarkScopePointOfInterest;
9999

100100
NSURLSessionDataTask *task = [geocoder geocodeWithOptions:options
101-
completionHandler:^(NSArray<MBPlacemark *> * _Nullable placemarks,
101+
completionHandler:^(NSArray<MBGeocodedPlacemark *> * _Nullable placemarks,
102102
NSString * _Nullable attribution,
103103
NSError * _Nullable error) {
104104
MBPlacemark *placemark = placemarks[0];
@@ -149,7 +149,7 @@ MBReverseGeocodeOptions *options = [[MBReverseGeocodeOptions alloc] initWithCoor
149149
// Or perhaps: [[MBReverseGeocodeOptions alloc] initWithLocation:locationManager.location]
150150

151151
NSURLSessionDataTask *task = [geocoder geocodeWithOptions:options
152-
completionHandler:^(NSArray<MBPlacemark *> * _Nullable placemarks,
152+
completionHandler:^(NSArray<MBGeocodedPlacemark *> * _Nullable placemarks,
153153
NSString * _Nullable attribution,
154154
NSError * _Nullable error) {
155155
MBPlacemark *placemark = placemarks[0];

0 commit comments

Comments
 (0)