0

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

mahdiTGK
  • 53
  • 7
  • did you add NSLocationWhenInUseUsageDescription in your Info.plist file? – meowmeowmeow Sep 04 '16 at 11:42
  • yes.but i use simulator and must set custom location !! – mahdiTGK Sep 07 '16 at 07:35
  • Please check it out this answer... [MohitTomariOSLocationManagerInstalltionStackoverFlow](http://stackoverflow.com/questions/25916841/cllocationmanager-startupdatinglocation-not-calling-locationmanagerdidupdateloc/26604933#26604933) – Mohit Tomar Sep 23 '16 at 07:00

0 Answers0