@@ -68,13 +68,14 @@ open class Placemark: NSObject, Codable {
6868 private enum CodingKeys : String , CodingKey {
6969 case identifier = " id "
7070 case name = " text "
71- case address = " address "
71+ case address
7272 case qualifiedName = " place_name "
7373 case superiorPlacemarks = " context "
74- case center = " center "
74+ case center
7575 case code = " short_code "
7676 case wikidataItemIdentifier = " wikidata "
77- case properties = " properties "
77+ case properties
78+ case boundingBox = " bbox "
7879 }
7980
8081 /**
@@ -99,6 +100,12 @@ open class Placemark: NSObject, Codable {
99100 }
100101
101102 properties = try container. decodeIfPresent ( Properties . self, forKey: . properties)
103+
104+ if let boundingBox = try container. decodeIfPresent ( [ CLLocationDegrees ] . self, forKey: . boundingBox) {
105+ let southWest = CLLocationCoordinate2D ( geoJSON: Array ( boundingBox. prefix ( 2 ) ) )
106+ let northEast = CLLocationCoordinate2D ( geoJSON: Array ( boundingBox. suffix ( 2 ) ) )
107+ region = RectangularRegion ( southWest: southWest, northEast: northEast)
108+ }
102109 }
103110
104111 public func encode( to encoder: Encoder ) throws {
@@ -214,9 +221,7 @@ open class Placemark: NSObject, Codable {
214221
215222 When this property is not `nil`, it is currently always a `RectangularRegion`. In the future, it may be another type of `CLRegion`.
216223 */
217- @objc open var region : CLRegion ? {
218- return nil
219- }
224+ @objc open var region : CLRegion ?
220225
221226 // MARK: Accessing Contact Information
222227
@@ -363,11 +368,13 @@ struct Properties: Codable {
363368 case phoneNumber = " tel "
364369 case maki
365370 case address
371+ case category
366372 }
367373 let shortCode : String ?
368374 let maki : String ?
369375 let phoneNumber : String ?
370376 let address : String ?
377+ let category : String ?
371378}
372379
373380/**
@@ -388,60 +395,47 @@ open class GeocodedPlacemark: Placemark {
388395 return ( superiorPlacemarks? . map { $0. name } ?? [ ] ) . reversed ( ) + [ name]
389396 }
390397
391- @objc open override var region : CLRegion ? {
392- // TODO: Fix!
393- // guard let boundingBox = featureJSON["bbox"] as? [Double] else {
394- // return nil
395- // }
396- //
397- // assert(boundingBox.count == 4)
398- // let southWest = CLLocationCoordinate2D(geoJSON: Array(boundingBox.prefix(2)))
399- // let northEast = CLLocationCoordinate2D(geoJSON: Array(boundingBox.suffix(2)))
400- let s = CLLocationCoordinate2D ( latitude: 0 , longitude: 0 )
401- return RectangularRegion ( southWest: s, northEast: s)
402- }
403-
404- // @objc open override var name: String {
405- // let text = super.name
406- //
407- // // 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.
408- // if let houseNumber = featureJSON["address"] as? String, scope == .address {
409- // let streetName = text
410- // let reversedAddress = "\(streetName) \(houseNumber)"
411- // if qualifiedNameComponents.contains(reversedAddress) {
412- // return reversedAddress
413- // } else {
414- // return "\(houseNumber) \(streetName)"
415- // }
416- // } else {
417- // return text
418- // }
419- // }
398+ @objc open override var name : String {
399+ get {
400+ let text = super. name
401+ // 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.
402+ if let houseNumber = self . address, scope == . address {
403+ let streetName = text
404+ let reversedAddress = " \( streetName) \( houseNumber) "
405+ if qualifiedNameComponents. contains ( reversedAddress) {
406+ return reversedAddress
407+ } else {
408+ return " \( houseNumber) \( streetName) "
409+ }
410+ } else {
411+ return text
412+ }
413+ } set {
414+ super. name = name
415+ }
416+ }
420417
421418 @objc open override var genres : [ String ] ? {
422- // TODO: Fix
423- // let categoryList = propertiesJSON["category"] as? String
424- // return categoryList?.components(separatedBy: ", ")
425- return [ " " ]
419+ return properties? . category? . components ( separatedBy: " , " )
426420 }
427421
428422 @objc open override var imageName : String ? {
429- // TODO: Fix
430- //return propertiesJSON["maki"] as? String
431- return " "
423+ return properties? . maki
432424 }
433425
434426 private var clippedAddressLines : [ String ] {
435- // let lines = qualifiedNameComponents
436- // if scope == .address {
437- // return lines
438- // }
439- // guard qualifiedName.contains(", ") else {
440- // // Chinese addresses have no commas and are reversed.
441- // return Array(lines.prefix(lines.count))
442- // }
443- // return Array(lines.suffix(from: 1))
444- return [ " " ]
427+ let lines = qualifiedNameComponents
428+ if scope == . address {
429+ return lines
430+ }
431+
432+ guard let qualifiedName = qualifiedName,
433+ qualifiedName. contains ( " , " ) else {
434+ // Chinese addresses have no commas and are reversed.
435+ return Array ( lines. prefix ( lines. count) )
436+ }
437+
438+ return Array ( lines. suffix ( from: 1 ) )
445439 }
446440
447441 override var formattedAddressLines : [ String ] {
@@ -506,8 +500,7 @@ open class GeocodedPlacemark: Placemark {
506500 The phone number to contact a business at this location.
507501 */
508502 @objc open override var phoneNumber : String ? {
509- //return propertiesJSON["tel"] as? String
510- return " "
503+ return properties? . phoneNumber
511504 }
512505}
513506
0 commit comments