After Completing some location based iPhone application, found that Core Location is a powerful & simple api provided with the iOS framework. By the help of CoreLocation.framework we can find out the current location of the user.As a developer we can develope lots of applications with the this simple CoreLocation framework. According to apple definition
“The Core Location framework lets you determine the current location or heading associated with a device. The framework uses the available hardware to determine the user’s position and heading. You use the classes and protocols in this framework to configure and schedule the delivery of location and heading events. You can also use it to define geographic regions and monitor when the user crosses the boundaries of those regions.”
This tutorial will cover how to get user location data using the iPhone sdk. now let get start
Goal of the Application
This tutorial is to build the super simple application “Where Am I?” . This application will shows you the current location of your device in the screen( Latitude and longitude values) and also when you moved it will update the current user locations. After finishing this tutorial i will explain how we can integrate this geolocation values to the google API and retrieve data from the google api(like Hospital finder app in appstore).
Step 1: Creating the Project
Let get started, Create a single view based iPhone application and name it is “Where Am I”.
Step 2: Add UI elements to the XIB
Now we need to add some UIlabel to the ViewController.xib to show the Latitude and longitude of the user.
now we need to create the corresponding IBoutlets in the viewcontroller.h file and wire it according to the correct outlets.
After that we need to synthesis. Now we need to add the CoreLocation.framework to the project. For that double click on the project file in the project navigation explorer, Click the “Where Am I” build under the target, Now we need to select the build phase and expand the link binary with libraries and click on add button below it. It will pop up the available iOS frameworks and we need to select the CoreLocation.framework from that and click Add.
Now we need to import the #import in to ViewController.h and also need to create an instance of CLLocationManager.
Now we need to allocate and initialize the CLLocationManager in the viewDidLoad.
If you look at the delegate protocol you will see there are several methods that can be implemented, but really the only one that we need to implement is:
Now we are going to implement the delegate method for getting the user location and set the latitudeLabel and longitudeLabel values from the new location coordinates.
Next we will add two buttons and create its corresponding IBAction methods for start and stop CLLocationManager and wire it with the corresponding outlets.
No comments:
Post a Comment