Saturday, October 24, 2015

CLLocationCoordinate2DIsValid - Check the validity of the default user location

This post shows how to:

1. Initialize the default user location with an invalid coordinate
2. Then check for the validity of the location.

let myLocation = CLLocation(latitude: kCLLocationCoordinate2DInvalid.latitude, longitude: kCLLocationCoordinate2DInvalid.longitude)

if CLLocationCoordinate2DIsValid(myLocation.coordinate) {
    println("myLocation is valid!!")
} else {
    println("myLocation is invalid!!")


If the user does not permit the device to access his/her location while using the app, the result is:

myLocation is invalid!!

No comments:

Post a Comment