-1

Hey I have some coordinates ["37.7", "-122.4"] that I am trying to use to reverse geoCode. So I can get the city and state for a simple UI Label. However when I use CLLocation to get the state via the administrativeArea var/method that comes standard with a placeMark it returns nil.

▿ some : 1 element - 0 : San Francisco Bay, San Francisco Bay, San Francisco, United States @ <+37.80000000,-122.50000000> +/- 100.00m, region CLCircularRegion (identifier:'<+37.79999999,-122.50000000> radius 141.72', center:<+37.79999999,-122.50000000>, radius:141.72m)

This is what I get back from the completion handler. Which makes it obvious that there is no state that is getting returned from this. Why would that be and how can I still get the state.

Enclosed is the block of code that controls this acton all help is appreciated.

 CLGeocoder().reverseGeocodeLocation(location, completionHandler: { (placeMark, error) in
            if error != nil{
                print("There was an error")
            }else{
                if let place = placeMark?[0]{
                    print(place)
                    print(place.locality ?? "")
                    print(place.subAdministrativeArea ?? "")
                    let myAttribute = [NSAttributedStringKey.font:UIFont(name: "Times New Roman", size: 15.3)!]
                    let myAttrString = NSAttributedString(string: place.locality ?? "", attributes: myAttribute)
                    locLabel.attributedText = myAttrString
                }
            }

        })
Ron Baker
  • 381
  • 6
  • 16

1 Answers1

0

You are interacting with an online database. This entry in the database has no state. That's somewhat understandable, because you seem to be in a body of water that's part of the Pacific Ocean; it isn't within the territory of a state. However, whether that's the reason or it's just a quirk or error in the database, there's nothing you can do about it. You've chosen to use this database and you must accept what it gives you.

matt
  • 515,959
  • 87
  • 875
  • 1,141