Skip to content

Commit d8802bc

Browse files
authored
Merge pull request #185 from mapbox/1ec5-precision
Add precision property to Placemark
2 parents e786dc4 + dd3c211 commit d8802bc

File tree

6 files changed

+94
-5
lines changed

6 files changed

+94
-5
lines changed

MapboxGeocoder.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@
113113
DA737B011E599C2C00AD2CDE /* OHHTTPStubs.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA737AFC1E599BB300AD2CDE /* OHHTTPStubs.framework */; };
114114
DA737B041E599C4A00AD2CDE /* OHHTTPStubs.framework.dSYM in CopyFiles */ = {isa = PBXBuildFile; fileRef = DA737AFF1E599BD400AD2CDE /* OHHTTPStubs.framework.dSYM */; };
115115
DA737B051E599C6B00AD2CDE /* OHHTTPStubs.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA737AFA1E599B9D00AD2CDE /* OHHTTPStubs.framework */; };
116+
DA8B5C07225FB2F400CD1C99 /* MBPlacemarkPrecision.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8B5C05225FB2F400CD1C99 /* MBPlacemarkPrecision.h */; settings = {ATTRIBUTES = (Public, ); }; };
117+
DA8B5C08225FB2F400CD1C99 /* MBPlacemarkPrecision.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8B5C05225FB2F400CD1C99 /* MBPlacemarkPrecision.h */; settings = {ATTRIBUTES = (Public, ); }; };
118+
DA8B5C09225FB2F400CD1C99 /* MBPlacemarkPrecision.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8B5C05225FB2F400CD1C99 /* MBPlacemarkPrecision.h */; settings = {ATTRIBUTES = (Public, ); }; };
119+
DA8B5C0A225FB2F400CD1C99 /* MBPlacemarkPrecision.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8B5C05225FB2F400CD1C99 /* MBPlacemarkPrecision.h */; settings = {ATTRIBUTES = (Public, ); }; };
120+
DA8B5C0B225FB2F400CD1C99 /* MBPlacemarkPrecision.m in Sources */ = {isa = PBXBuildFile; fileRef = DA8B5C06225FB2F400CD1C99 /* MBPlacemarkPrecision.m */; };
121+
DA8B5C0C225FB2F400CD1C99 /* MBPlacemarkPrecision.m in Sources */ = {isa = PBXBuildFile; fileRef = DA8B5C06225FB2F400CD1C99 /* MBPlacemarkPrecision.m */; };
122+
DA8B5C0D225FB2F400CD1C99 /* MBPlacemarkPrecision.m in Sources */ = {isa = PBXBuildFile; fileRef = DA8B5C06225FB2F400CD1C99 /* MBPlacemarkPrecision.m */; };
123+
DA8B5C0E225FB2F400CD1C99 /* MBPlacemarkPrecision.m in Sources */ = {isa = PBXBuildFile; fileRef = DA8B5C06225FB2F400CD1C99 /* MBPlacemarkPrecision.m */; };
116124
DAA75ED620DDAD760049807C /* MapboxGeocoder.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDC2470419A1C3B40054B0C0 /* MapboxGeocoder.framework */; };
117125
DAA75ED720DDAD760049807C /* MapboxGeocoder.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DDC2470419A1C3B40054B0C0 /* MapboxGeocoder.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
118126
DAF158851D03D81600829B35 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DAF158841D03D81600829B35 /* Launch Screen.storyboard */; };
@@ -249,6 +257,8 @@
249257
DA737AFA1E599B9D00AD2CDE /* OHHTTPStubs.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OHHTTPStubs.framework; path = Carthage/Build/tvOS/OHHTTPStubs.framework; sourceTree = "<group>"; };
250258
DA737AFC1E599BB300AD2CDE /* OHHTTPStubs.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OHHTTPStubs.framework; path = Carthage/Build/Mac/OHHTTPStubs.framework; sourceTree = "<group>"; };
251259
DA737AFF1E599BD400AD2CDE /* OHHTTPStubs.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = OHHTTPStubs.framework.dSYM; path = Carthage/Build/Mac/OHHTTPStubs.framework.dSYM; sourceTree = "<group>"; };
260+
DA8B5C05225FB2F400CD1C99 /* MBPlacemarkPrecision.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBPlacemarkPrecision.h; sourceTree = "<group>"; };
261+
DA8B5C06225FB2F400CD1C99 /* MBPlacemarkPrecision.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBPlacemarkPrecision.m; sourceTree = "<group>"; };
252262
DAF158841D03D81600829B35 /* Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
253263
DD342B5019A140EE00219F77 /* Geocoder (Swift).app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Geocoder (Swift).app"; sourceTree = BUILT_PRODUCTS_DIR; };
254264
DD342B5419A140EE00219F77 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -415,6 +425,8 @@
415425
DA2EC05D1CED732F00D4BA5D /* MBGeocodeOptions.swift */,
416426
DDC229591A36073B006BE405 /* MBGeocoder.swift */,
417427
DA2E03EF1CB0FDB400D1269A /* MBPlacemark.swift */,
428+
DA8B5C05225FB2F400CD1C99 /* MBPlacemarkPrecision.h */,
429+
DA8B5C06225FB2F400CD1C99 /* MBPlacemarkPrecision.m */,
418430
DA29C8DE1CEBE90200E48A61 /* MBPlacemarkScope.h */,
419431
DA2EC05B1CED72E900D4BA5D /* MBPlacemarkScope.swift */,
420432
DA2E03F11CB0FE0200D1269A /* MBRectangularRegion.swift */,
@@ -502,6 +514,7 @@
502514
files = (
503515
DA5170AD1CF1B1DB00CD6DCF /* MapboxGeocoder.h in Headers */,
504516
DA5170B11CF1B1E000CD6DCF /* MBPlacemarkScope.h in Headers */,
517+
DA8B5C08225FB2F400CD1C99 /* MBPlacemarkPrecision.h in Headers */,
505518
);
506519
runOnlyForDeploymentPostprocessing = 0;
507520
};
@@ -511,6 +524,7 @@
511524
files = (
512525
DA5170D81CF2541C00CD6DCF /* MapboxGeocoder.h in Headers */,
513526
DA5170DC1CF2541C00CD6DCF /* MBPlacemarkScope.h in Headers */,
527+
DA8B5C09225FB2F400CD1C99 /* MBPlacemarkPrecision.h in Headers */,
514528
);
515529
runOnlyForDeploymentPostprocessing = 0;
516530
};
@@ -520,6 +534,7 @@
520534
files = (
521535
DA5170F31CF2582F00CD6DCF /* MapboxGeocoder.h in Headers */,
522536
DA5170F71CF2582F00CD6DCF /* MBPlacemarkScope.h in Headers */,
537+
DA8B5C0A225FB2F400CD1C99 /* MBPlacemarkPrecision.h in Headers */,
523538
);
524539
runOnlyForDeploymentPostprocessing = 0;
525540
};
@@ -529,6 +544,7 @@
529544
files = (
530545
DA29C8DF1CEBE90200E48A61 /* MBPlacemarkScope.h in Headers */,
531546
DDC2295C1A36074F006BE405 /* MapboxGeocoder.h in Headers */,
547+
DA8B5C07225FB2F400CD1C99 /* MBPlacemarkPrecision.h in Headers */,
532548
);
533549
runOnlyForDeploymentPostprocessing = 0;
534550
};
@@ -973,6 +989,7 @@
973989
DA5170AF1CF1B1E000CD6DCF /* MBGeocoder.swift in Sources */,
974990
DA5170B21CF1B1E000CD6DCF /* MBPlacemarkScope.swift in Sources */,
975991
DA5170AE1CF1B1E000CD6DCF /* MBGeocodeOptions.swift in Sources */,
992+
DA8B5C0C225FB2F400CD1C99 /* MBPlacemarkPrecision.m in Sources */,
976993
35D3DE3A2112410A00B62912 /* CoreLocation.swift in Sources */,
977994
);
978995
runOnlyForDeploymentPostprocessing = 0;
@@ -999,6 +1016,7 @@
9991016
DA5170DA1CF2541C00CD6DCF /* MBGeocoder.swift in Sources */,
10001017
DA5170DD1CF2541C00CD6DCF /* MBPlacemarkScope.swift in Sources */,
10011018
DA5170D91CF2541C00CD6DCF /* MBGeocodeOptions.swift in Sources */,
1019+
DA8B5C0D225FB2F400CD1C99 /* MBPlacemarkPrecision.m in Sources */,
10021020
35D3DE3B2112410A00B62912 /* CoreLocation.swift in Sources */,
10031021
);
10041022
runOnlyForDeploymentPostprocessing = 0;
@@ -1025,6 +1043,7 @@
10251043
DA5170F51CF2582F00CD6DCF /* MBGeocoder.swift in Sources */,
10261044
DA5170F81CF2582F00CD6DCF /* MBPlacemarkScope.swift in Sources */,
10271045
DA5170F41CF2582F00CD6DCF /* MBGeocodeOptions.swift in Sources */,
1046+
DA8B5C0E225FB2F400CD1C99 /* MBPlacemarkPrecision.m in Sources */,
10281047
35D3DE3C2112410A00B62912 /* CoreLocation.swift in Sources */,
10291048
);
10301049
runOnlyForDeploymentPostprocessing = 0;
@@ -1047,6 +1066,7 @@
10471066
DDC2295E1A360843006BE405 /* MBGeocoder.swift in Sources */,
10481067
DA2EC05C1CED72E900D4BA5D /* MBPlacemarkScope.swift in Sources */,
10491068
DA2E03F01CB0FDB400D1269A /* MBPlacemark.swift in Sources */,
1069+
DA8B5C0B225FB2F400CD1C99 /* MBPlacemarkPrecision.m in Sources */,
10501070
35D3DE392112410A00B62912 /* CoreLocation.swift in Sources */,
10511071
);
10521072
runOnlyForDeploymentPostprocessing = 0;

MapboxGeocoder/MBGeocoder.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ extension CharacterSet {
6262
Returns the character set including the characters allowed in the “geocoding query” (file name) part of a Geocoding API URL request.
6363
*/
6464
internal static func geocodingQueryAllowedCharacterSet() -> CharacterSet {
65-
// <rdar://problem/26880260> <https://openradar.appspot.com/26880260>
66-
return CharacterSet(charactersIn: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
67-
// var characterSet = CharacterSet.urlPathAllowed
68-
// characterSet.remove(charactersIn: "/;")
69-
// return characterSet
65+
var characterSet = CharacterSet.urlPathAllowed
66+
characterSet.remove(charactersIn: "/;")
67+
return characterSet
7068
}
7169
}
7270

MapboxGeocoder/MBPlacemark.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public let MBPostalAddressCountryKey = "country"
5959
*/
6060
public let MBPostalAddressISOCountryCodeKey = "ISOCountryCode"
6161

62+
public typealias PlacemarkPrecision = MBPlacemarkPrecision
63+
6264
/**
6365
A `Placemark` object represents a geocoder result. A placemark associates identifiers, geographic data, and contact information with a particular latitude and longitude. It is possible to explicitly create a placemark object from another placemark object; however, placemark objects are generally created for you via the `Geocoder.geocode(_:completionHandler:)` method.
6466
*/
@@ -376,6 +378,7 @@ internal struct Properties: Codable {
376378
case phoneNumber = "tel"
377379
case maki
378380
case address
381+
case precision = "accuracy"
379382
case category
380383
case wikidata
381384
}
@@ -384,6 +387,7 @@ internal struct Properties: Codable {
384387
let maki: String?
385388
let phoneNumber: String?
386389
let address: String?
390+
let precision: String?
387391
let category: String?
388392
let wikidata: String?
389393
}
@@ -481,6 +485,9 @@ open class GeocodedPlacemark: Placemark {
481485
} else {
482486
return "\(houseNumber) \(streetName)"
483487
}
488+
} else if scope == .address, precision == .intersection {
489+
// For intersection features, `text` is just the first street name. The first line of the fully qualified address contains the cross street too.
490+
return qualifiedNameComponents.first ?? text
484491
} else {
485492
return text
486493
}
@@ -580,6 +587,18 @@ open class GeocodedPlacemark: Placemark {
580587
@objc open override var phoneNumber: String? {
581588
return properties?.phoneNumber
582589
}
590+
591+
/**
592+
The placemark’s precision.
593+
594+
The precision offers a general indication of the potential distance between the `location` property and the feature’s actual real-world location.
595+
*/
596+
@objc open var precision: PlacemarkPrecision? {
597+
if let precision = properties?.precision {
598+
return PlacemarkPrecision(rawValue: precision)
599+
}
600+
return nil
601+
}
583602
}
584603

585604
/**
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#import <Foundation/Foundation.h>
2+
3+
NS_ASSUME_NONNULL_BEGIN
4+
5+
/**
6+
An indication of a placemark’s precision.
7+
8+
A placemark’s `MBPlacemarkScope` indicates a feature’s size or importance,
9+
whereas its precision indicates how far the reported location may be from the
10+
actual real-world location.
11+
*/
12+
typedef NSString *MBPlacemarkPrecision NS_TYPED_EXTENSIBLE_ENUM;
13+
14+
/**
15+
The placemark represents a specific building with a location on the
16+
building’s rooftop or at one of its entrances.
17+
*/
18+
extern MBPlacemarkPrecision const MBPlacemarkPrecisionBuilding;
19+
20+
/**
21+
The placemark represents a tract or parcel of land with a location at the
22+
centroid.
23+
*/
24+
extern MBPlacemarkPrecision const MBPlacemarkPrecisionParcel;
25+
26+
/**
27+
The placemark represents an address that has been interpolated from an address
28+
range. The actual location is generally somewhere along the same block of the
29+
same street as the placemark’s location.
30+
*/
31+
extern MBPlacemarkPrecision const MBPlacemarkPrecisionInterpolated;
32+
33+
/**
34+
The placemark represents a block along a street or an intersection between two
35+
or more streets.
36+
*/
37+
extern MBPlacemarkPrecision const MBPlacemarkPrecisionIntersection;
38+
39+
/*
40+
The placemark represents an entire street with a location at its midpoint.
41+
*/
42+
extern MBPlacemarkPrecision const MBPlacemarkPrecisionStreet;
43+
44+
NS_ASSUME_NONNULL_END
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#import "MBPlacemarkPrecision.h"
2+
3+
MBPlacemarkPrecision const MBPlacemarkPrecisionBuilding = @"rooftop";
4+
MBPlacemarkPrecision const MBPlacemarkPrecisionParcel = @"parcel";
5+
MBPlacemarkPrecision const MBPlacemarkPrecisionInterpolated = @"interpolated";
6+
MBPlacemarkPrecision const MBPlacemarkPrecisionIntersection = @"intersection";
7+
MBPlacemarkPrecision const MBPlacemarkPrecisionStreet = @"street";

MapboxGeocoder/MapboxGeocoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ FOUNDATION_EXPORT double MapboxGeocoderVersionNumber;
88

99
FOUNDATION_EXPORT const unsigned char MapboxGeocoderVersionString[];
1010

11+
#import "MBPlacemarkPrecision.h"
1112
#import "MBPlacemarkScope.h"

0 commit comments

Comments
 (0)