ios - Can't get correct city name in swift with CLGeocoder -


i tried current city name , country name swift. here's source code. // in cllocationmanagerdelegate method can user's current location coordinates:

func locationmanager(manager: cllocationmanager, didupdatelocations locations: [cllocation]) {     let locvalue:cllocationcoordinate2d = manager.location!.coordinate     print("locations = \(locvalue.latitude) \(locvalue.longitude)")     self.locationmanager.stopupdatinglocation()     getaddressfromgeocodecoordinate(manager.location!)  }  func getaddressfromgeocodecoordinate(locationobj: cllocation) {     let geocoder = clgeocoder()     geocoder.reversegeocodelocation(locationobj, completionhandler: { (placemarks, error) -> void in          // place details         var placemark: clplacemark!         placemark = placemarks?[0]          // address dictionary         print(placemark.addressdictionary)          // city         if let city = placemark.addressdictionary!["city"] as? nsstring {             print("city:",city)         }          // country         if let country = placemark.addressdictionary!["country"] as? nsstring {             print("country", country)         }      }) } 

but when want print city returns nil. trid placemark.subadministrativearea returns nil.

i'm located in dandong city.

my code prints country well. country china city.

anybody knows solution?

check if error or what's response of getting print(placemark.addressdictionary)

geocoder.reversegeocodelocation(newlocation, completionhandler: {(stuff, error)->void in          if error {             println("reverse geodcode fail: \(error.localizeddescription)")             return         }          if stuff.count > 0 {             self.placemark = clplacemark(placemark: stuff[0] clplacemark)              self.addresslabel.text = string(format:"%@ %@\n%@ %@ %@\n%@",                 self.placemark.subthoroughfare ? self.placemark.subthoroughfare : "" ,                 self.placemark.thoroughfare ? self.placemark.thoroughfare : "",                 self.placemark.locality ? self.placemark.locality : "",                 self.placemark.postalcode ? self.placemark.postalcode : "",                 self.placemark.administrativearea ? self.placemark.administrativearea : "",                 self.placemark.country ? self.placemark.country : "")         }         else {             println("no placemarks!")             return         }          }) 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -