D
D
Daniil Chepenko2015-11-30 12:08:01
Swift
Daniil Chepenko, 2015-11-30 12:08:01

How to test geolocation?

Made a location function.
However, the program crashes when geolocation is turned off.
What eksepsheny prescribe usually?
I tried to write something with myths

CLLocationManager.locationServicesEnabled() == true)

But it always returns true.
What do you advise?
If so, here is the button code:
@IBAction func CurrentLocation(sender: AnyObject) {
        
        if (CLLocationManager.locationServicesEnabled() == true) {
            let userLocation = locationmanager.location
        
            let center = CLLocationCoordinate2D(latitude: userLocation!.coordinate.latitude, longitude: userLocation!.coordinate.longitude)
        
            var currentAnnotation = MKPointAnnotation()
            currentAnnotation.coordinate = center
            currentAnnotation.title = "You're here!"
        
            MapApple.addAnnotation(currentAnnotation)
            
            print("location is enabled")
        }
        
        else {
            print("location is diable")
            let AlertButton = UIAlertController(title: "Geo", message: "You need to switch it on", preferredStyle: .Alert)
            
        }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question