my code
in func viewDidLoad >> is:
manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
and I define func location manager like this:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let mylocation:CLLocation = manager.location!
let mylatatiude:CLLocationDegrees = mylocation.coordinate.latitude
let mylongitude:CLLocationDegrees = mylocation.coordinate.longitude
let mydetlalatatude:CLLocationDegrees = 0.01
let mydetlongitude:CLLocationDegrees = 0.01
let myspan:MKCoordinateSpan = MKCoordinateSpanMake(mydetlalatatude, mydetlongitude)
let mycurrentlocation :CLLocationCoordinate2D = CLLocationCoordinate2DMake(mylatatiude, mylongitude)
let myregion:MKCoordinateRegion = MKCoordinateRegionMake(mycurrentlocation, myspan)
mapview.setRegion(myregion, animated: true)
manager.stopUpdatingLocation()
then ,I will pins my location like this:
let WonderAnnotation = MKPointAnnotation()
WonderAnnotation.coordinate = mycurrentlocation
WonderAnnotation.title="here you are"
mapview.addAnnotation(WonderAnnotation)
and I want show my address
CLGeocoder().reverseGeocodeLocation(mylocation, completionHandler: { (placemarks, error) in
if(error != nil){
print("error: \(error)")}
else {
let p = CLPlacemark(placemark: (placemarks?[0] as CLPlacemark!))
var subthoroughFare:String = ""
var thoroughfrae:String=""
var sublocality:String=""
var subadministrativearea:String=""
var postalcode:String=""
var country:String = ""
if ((p.subThoroughfare) != nil){
subthoroughFare = (p.subThoroughfare)!
}
if (p.thoroughfare != nil){
thoroughfrae = p.thoroughfare!
}
if (p.subLocality != nil){
sublocality = p.subLocality!
}
if (p.subAdministrativeArea != nil){
subadministrativearea = p.administrativeArea!
}
if ((p.postalCode) != nil){
postalcode = p.postalCode!
}
if ((p.country) != nil){
country = p.country!
} self.info = "\(subthoroughFare)\(thoroughfrae)\(sublocality)\(subadministrativearea)\(postalcode)\n\(country)"
}
}
)
}
this code not syntax error but it's not working well!
& not show my location