diff --git a/MapboxGeocoder/MBPlacemark.swift b/MapboxGeocoder/MBPlacemark.swift index 2668efe..7a520d1 100644 --- a/MapboxGeocoder/MBPlacemark.swift +++ b/MapboxGeocoder/MBPlacemark.swift @@ -405,6 +405,7 @@ open class GeocodedPlacemark: Placemark { private enum CodingKeys: String, CodingKey { case routableLocations = "routable_points" + case relevance } private enum PointsCodingKeys: String, CodingKey { @@ -421,8 +422,6 @@ open class GeocodedPlacemark: Placemark { @objc open var routableLocations: [CLLocation]? public required init(from decoder: Decoder) throws { - try super.init(from: decoder) - let container = try decoder.container(keyedBy: CodingKeys.self) if let pointsContainer = try? container.nestedContainer(keyedBy: PointsCodingKeys.self, forKey: .routableLocations), @@ -433,13 +432,17 @@ open class GeocodedPlacemark: Placemark { routableLocations = [CLLocation(coordinate: coordinate)] } } + + relevance = try container.decodeIfPresent(Double.self, forKey: .relevance) ?? -1 + + try super.init(from: decoder) } public override func encode(to encoder: Encoder) throws { - try super.encode(to: encoder) - var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(relevance, forKey: .relevance) + if let routableLocations = routableLocations, !routableLocations.isEmpty { var pointsContainer = container.nestedContainer(keyedBy: PointsCodingKeys.self, forKey: .routableLocations) @@ -448,6 +451,8 @@ open class GeocodedPlacemark: Placemark { routableLocations[0].coordinate.latitude]) try coordinatesContainer.encode(routableLocation) } + + try super.encode(to: encoder) } @objc open override var debugDescription: String { @@ -486,6 +491,8 @@ open class GeocodedPlacemark: Placemark { return properties?.maki } + open var relevance: Double? + private var clippedAddressLines: [String] { let lines = qualifiedNameComponents if scope == .address { diff --git a/MapboxGeocoder/MBPlacemarkScope.swift b/MapboxGeocoder/MBPlacemarkScope.swift index bec41a3..1335898 100644 --- a/MapboxGeocoder/MBPlacemarkScope.swift +++ b/MapboxGeocoder/MBPlacemarkScope.swift @@ -24,7 +24,6 @@ extension PlacemarkScope: CustomStringConvertible { scope.update(with: .neighborhood) case "address": scope.update(with: .address) - case "poi.landmark": scope.update(with: .landmark) case "poi": diff --git a/MapboxGeocoderTests/ForwardGeocodingTests.swift b/MapboxGeocoderTests/ForwardGeocodingTests.swift index 4511e74..fa29aa9 100644 --- a/MapboxGeocoderTests/ForwardGeocodingTests.swift +++ b/MapboxGeocoderTests/ForwardGeocodingTests.swift @@ -41,7 +41,7 @@ class ForwardGeocodingTests: XCTestCase { XCTAssertEqual(addressPlacemark.routableLocations![0].coordinate.longitude, CLLocationDegrees(138.995284)) XCTAssertEqual(addressPlacemark.routableLocations![0].coordinate.latitude, CLLocationDegrees(-34.470403)) - + XCTAssertEqual(addressPlacemark.relevance, 0.39, "Placeshould.relevance should be 0.39") XCTAssertEqual(addressPlacemark.description, "Pennsylvania Ave", "forward geocode should populate description") XCTAssertEqual(addressPlacemark.debugDescription, "Pennsylvania Ave, Wasaga Beach, Ontario L9Z 3A8, Canada", "forward geocode should populate debug description") XCTAssertEqual(addressPlacemark.name, "Pennsylvania Ave", "forward geocode should populate name")