In this tutorial we will expand on the previous Core Location tutorial. Here we will extract specific location attributes such as coordinates, altitude, and speed.

The CLLocation object contains several properties containing location details. These properties are:
altitude – type CLLocationDistance coordinate – type CLLocationCoordinate2D course – type CLLocationDirection horizontalAccuracy – type CLLocationAccuracy speed – type CLLocationSpeed timestamp – type NSDate verticalAccuracy – type CLLocationAccuracy
A quick look in CLLocation.h reveals several typedefs which should help you understand how to handle the data:
typedef double CLLocationAccuracy; typedef double CLLocationSpeed; typedef double CLLocationDirection; typedef double CLLocationDistance; typedef double CLLocationDegrees; typedef struct { CLLocationDegrees latitude; CLLocationDegrees longitude; } CLLocationCoordinate2D;
Just a bunch of doubles and a structure containing doubles.
This tutorial will focus on three of the above properties; coordinate, speed, and altitude.
Start by opening up the project in the previous tutorial. Compile and run on your iPhone to make sure everything works with your version of the SDK and device. Once that’s done, open up CoreLocationDemoViewController.h, remove the current IBOutlet and add four new IBOutlets of type UILabel for speed, latitude, longitude, and altitude.
@interface CoreLocationDemoViewController : UIViewController <CoreLocationControllerDelegate> { CoreLocationController *CLController; IBOutlet UILabel *speedLabel; IBOutlet UILabel *latitudeLabel; IBOutlet UILabel *longitudeLabel; IBOutlet UILabel *altitudeLabel; }
Open up CoreLocationDemoViewController.xib and delete the current UILabel. Create four new ones and link them up to the IBOutlets we just created. You can save and quit Interface Builder when you are done.

Open CoreLocationDemoViewController.m and clear the contents of locationUpdate: and locationError: and add the following code:
- (void)locationUpdate:(CLLocation *)location { speedLabel.text = [NSString stringWithFormat:@"SPEED: %f", [location speed]]; latitudeLabel.text = [NSString stringWithFormat:@"LATITUDE: %f", location.coordinate.latitude]; longitudeLabel.text = [NSString stringWithFormat:@"LONGITUDE: %f", location.coordinate.longitude]; altitudeLabel.text = [NSString stringWithFormat:@"ALTITUDE: %f", [location altitude]]; } - (void)locationError:(NSError *)error { speedLabel.text = [error description]; }
We simply set the UILabel text to a NSString containing the value of the given property.
For more information on CLLocation properties, visit Apple’s developer documentation page at:
http://developer.apple.com/iphone/library/documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html
[Demo Project Source: Core Location GPS Demo - 25k]
[Demo Project Source: Core Location GPS Demo Part 2 - 25k]
Random Posts:
- iAd Profit, the truth
- iStrobe Spawn #2 – iFlashlightLED
- Some recent hunts
- iStrobe accepted in App Store
- Happy Father’s Day!
If you found this useful, shoot me a small donation or at the very least leave a comment, every bit of encouragement helps keep me motivated to update with more content on a regular basis!
Tags: code, compass, core, corelocation, Development, gps, ios, iPhone, location, open, programming
You can skip to the end and leave a response. Pinging is currently not allowed.
[...] Click here for iOS Core Location GPS Tutorial Part 2 [...]
Wow this is a great resource.. I’m enjoying it.. good article
[...] Core Location GPS Tutorial Part 1 Core Location GPS Tutorial Part 2 [...]
This the code i write below
The error is show like this
ERROR,Time,305491182.961,Function,”void CLClientHandleDaemonDataRegistration(__CLClient*, mach_port_t, const CLDaemonCommToClientRegistration*, const __CFDictionary*)”,server did not accept client registration 2
ERROR,Time,305491183.102,Function,”void CLClientHandleDaemonDataRegistration(__CLClient*, mach_port_t, const CLDaemonCommToClientRegistration*, const __CFDictionary*)”,server did not accept client registration 2
please help me out to solve the problem
Thank you
manju, you need to click “Allow” when iOS asks if the app can use your current location. That is the problem. You can use [CLLocationManager locationServicesEnabled] to check if location services are enabled to prevent an error if someone clicks “Don’t Allow” when the app launches.
There may also be some issues with running in the simulator. Try on an actual device.
Are you using this on a GPS enabled device?
i put [CLLocationManager locationServicesEnabled] this line of code above this ” [MYlocation startUpdatingLocation]; ” line but it not work .
i am checking in the simulator 4.0but i download u code and run int the simulator it work correctly.
When i run my code i copped above code it give the the after compiling [MYlocation startUpdatingLocation]; this line it show the error
ERROR,Time,305491182.961,Function,”void CLClientHandleDaemonDataRegistration(__CLClient*, mach_port_t, const CLDaemonCommToClientRegistration*, const __CFDictionary*)”,server did not accept client registration 2
ERROR,Time,305491183.102,Function,”void CLClientHandleDaemonDataRegistration(__CLClient*, mach_port_t, const CLDaemonCommToClientRegistration*, const __CFDictionary*)”,server did not accept client registration 2
You didn’t answer whether or not you clicked “Allow” or “Don’t Allow” when prompted. Try cleaning all targets and rebuilding. Make sure to click “Allow” when prompted. You must have clicked “Don’t Allow” at some point.
i am told that that prompt is not showing it showing directly this error
thanks
and i am also clear the targets it is not working
Did you try it on a device?
yes i try in the i phone its not working
Thank you, this is one of the best iphone dev tutorials I’ve ever read.
hello Nick Vellios,
i want to find the distance between the two end point how should i get from the core location
please help me in this
thank you
Hello, Great example! has anyone been ablre to take this code and get the address from the lat long using mkreversegeocoder? i tried taking the current address sample from apple and combining it withthis, but am having no luck…
In order to add a map view to this vc, having produced no errors, what could anyone see in this that prevents centering, and zooming to the defined span?
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.0039;
span.longitudeDelta=0.0034;
CLLocationCoordinate2D locationStart;
region.span=span;
region.center=locationStart;
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
Your tutorials are so clear and detailed. Thank you for everything you provide here.
What a nice post. I really love reading these types or articles. I can?t wait to see what others have to say.
As a Newbie, I am always searching online for articles that can help me. Thank you
This was a great tutorial!
Made things much clearer than the other tutorials on location manager that I´ve seen, and really helped me understand the principles.
Just skimming through your blog. It’s really well put togehter and these tutorials have been very informative for me (just getting into objc) so thank you
Great information! I’ve been looking for something like this for a while now. Thanks!
This is nice tutorial.I hve downloaded ur source code when i run on simulator 4.it is showing error domain=KCLerrordomain code=0 “The Operation cou…”
why it is showing this error?
Simulator: 4.0
ipodTouch with iOS 3.1
Location service is ON, allowed
On all the two I get the following error: Error Domain=kCLErrorDomain Code=0 “The operation could not..”
Is there a problem with my WIFI or ipod?
Thanks. It’s very good but I wonder that why it takes time to initialize GPS in the first time? When I walk about 100meters GPS just start.
Hi, first of all, thank you so much for this great tutorial and specially for sharing, actually i did identically like you did, no problem but when i run i see the view with the label empty showing nothing
can you help me please, thx in advance
Thanks for a great tutorial! Keep up the good work!
very but very good tutorial, but i am getting an error on both part one and part two. anyone came across this one?
server did not accept client registration 68
Thank you very much for the great tutorial – is it possible for you to explain how to format the speed string that it show km/h?
Thx a lot!
Hi, sir.
Your tutorial is great, but I cannot get accurate speed on device. I think i seem to set wrong distanceFilter and desiredAccuracy.
In my project, i set them as below.
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
Please help me!.
Hello,
thanks for this great tutorial!
I was wondering if you know any guides where you can make a audio file play, when the user enters a certain location?
I would like to develop a pod walk app for educational purposes.
greetings
Niklas
Very useful! Thanks for sharing this information!
Hi,the code is very helpful.
How can I modify this code so that it will run in Background continously.
Thank you for wonderful tutorial. How can I send my position via SMS or e-mail to a friend?
Thank you for help.
Very good article!!!
I’m still rather new with obj-c
This was very helpful, THANKS!!!
Very good tutorials. With your help I was able to do a my little first app for the app store. It’s free and it’s called Bike Dash.
Thanks!!