Google Android Development Agency SASS

Wednesday 6 May 2009

iPhone GPS programming is easy

Before I looked at GPS development for iPhone I was bracing myself for an onslaught of complicated hardware commands, old school C data structures and binary arithmetic. Queue a flashback to the CoreAudio learning curve...

Almost unbelievable it's not the case though; Apple have made things pretty straightforward for a change!

The first thing to do, and the key to it all, is to create a class which conforms to the CLLocationManagerDelegate specification:


@interface MyLocationManager : NSObject <CLLocationManagerDelegate> ...


The CLLocationManager delegate needs to contain a method which is called to notify it that the location has been updated. Basically, this:


- (void) locationManager:(CLLocationManager *) manager
didUpdateToLocation:(CLLocation *) newLocation
fromLocation:(CLLocation *) oldLocation {
...


Now within your method implementation you can access the coordinates of the old and new locations with:


newLocation.coordinate.latitude;
newLocation.coordinate.longitude;
newLocation.altitude;


Obviously you'll need to do a bit of jiggery pokery to get those raw figures into a useful state, but that's down to your own app logic. In terms of getting the GPS coordinates nothing could be easier!

Apple have a very good sample project in the developer library called LocateMe. I'd suggest you download it and study the code to learn the ins and outs of GPS programming. It took me literally 10 minutes to get the basics going.

Next stop - Android GPS development!

No comments:

Post a Comment