How to read the current location of an iOS device

Thanks to the Core Location framework we can get the current location of our device. We need to create a CLLocationManager object and start it. Its delegate method will return CLLocation objects which among other items will contain the longitude and latitude of our device.

Here’s how to do it. Let’s create the manager as a property (self.manager) and initialise it with this custom method:

In the first method all I’m doing is to display the longitude and latitude in two labels. Both are float values, derived from a CLLocation object that is available in the locations array (this is new in iOS 7). This array contains previous location objects as well and is amended every time this method is called. The most current location is at the end of the array (we get it via [locations lastObject]).