<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iPhone Programming Tutorials &#187; GPS</title>
	<atom:link href="/tag/gps/feed/" rel="self" type="application/rss+xml" />
	<link>http://icodeblog.com</link>
	<description>iPhone Programming Tutorials</description>
	<lastBuildDate>Tue, 19 Nov 2013 19:34:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>How to Add GPS to Your iOS App &#8211; Part 1</title>
		<link>http://icodeblog.com/2012/06/04/how-to-add-gps-to-your-ios-app-part-1/</link>
		<comments>http://icodeblog.com/2012/06/04/how-to-add-gps-to-your-ios-app-part-1/#comments</comments>
		<pubDate>Mon, 04 Jun 2012 21:33:11 +0000</pubDate>
		<dc:creator><![CDATA[Shawn Grimes]]></dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[CoreLocation]]></category>
		<category><![CDATA[GPS]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone Coding]]></category>
		<category><![CDATA[iphone dev]]></category>
		<category><![CDATA[iphone development]]></category>
		<category><![CDATA[iphone programming]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=3690</guid>
		<description><![CDATA[
In Part 1 of this series, I will introduce you to the very basics of CoreLocation services and getting the location of the device currently being used.
About CoreLocation
The CoreLocation framework provides your app with the ability to get a device&#8217;s current location, provided the user of the device has granted your app access to that information.
Location services are provided in two major ways using this framework:

Standard Location Services- This service provides the most accurate location information using a variety of  ...]]></description>
				<content:encoded><![CDATA[<p><center><img src="http://img.skitch.com/20120604-drip3tee432eccbfhsdkrpwhbr.jpg" alt="CoreLocation Graphic" /></center></p>
<blockquote><p>In Part 1 of this series, I will introduce you to the very basics of CoreLocation services and getting the location of the device currently being used.</p></blockquote>
<h2>About CoreLocation</h2>
<p>The CoreLocation framework provides your app with the ability to get a device&#8217;s current location, provided the user of the device has granted your app access to that information.</p>
<p>Location services are provided in two major ways using this framework:</p>
<ol>
<li><strong>Standard Location Services</strong>- This service provides the most accurate location information using a variety of methods including celluar, wifi, and GPS.
<ul>
<li>Most accurate.</li>
<li>Consumes the most power and can take a longer time to acquire.</li>
<li>Can only be used when your application is in the foreground.</li>
</ul>
</li>
<li><strong>Significant Change Location Services</strong>- This service uses cellular data to determine a general idea of where the device is located.
<ul>
<li>Fastest and uses the least amount of power to determine the location.</li>
<li>Can also be used to notify your app when a significant change in the location has occurred even if your app is not in focus.</li>
</ul>
</li>
</ol>
<h2>Project Files:</h2>
<p>You can download the project files at this github repository: <a href="http://github.com/shawngrimes/Location-and-Map-Sample">http://github.com/shawngrimes/Location-and-Map-Sample</a></p>
<h2>Adding Location Frameworks</h2>
<p>The first step to adding location services to your project is to add the CoreLocation framework.</p>
<div class="thumbnail" align="center"><a href="http://skitch.com/shawnegrimes/86jyp/link-binary-with-libraries"><img src="http://img.skitch.com/20120603-d7w4x5fyueprskt33g5xet7a1n.preview.jpg" alt="Link Binary With Libraries" /></a></div>
<ol>
<li>Select your target and go to the &#8220;Build Phases&#8221; tab.</li>
<li>Click the &#8220;+&#8221; button under &#8220;Link Binary With Libraries&#8221;</li>
<li>Select the CoreLocation framework and click &#8220;Add&#8221;</li>
</ol>
<div class="thumbnail" align="center"><a href="http://skitch.com/shawnegrimes/86je5/add-core-location-framework"><img src="http://img.skitch.com/20120603-gby2hyh3mtsfax86u5ht39491r.preview.jpg" alt="Add Core Location Framework" /></a></div>
<h2>Location Manager</h2>
<p>With location services, you create an instance of CLLocationManager. There is usually one instance of this per app so I feel a good place for this is in the App Delegate and then each view can access the current location from the App Delegate.</p>
<p>To start, open your App Delegate header file:</p>
<ol>
<li>Add <code>#import &lt;CoreLocation/CoreLocation.h&gt;</code> to the top</li>
<li>Specify that your app delegate complies with the Core Location Delegate protocol by changing your <code>@interface</code> line with <code>@interface CFAAppDelegate : UIResponder &lt;UIApplicationDelegate, CLLocationManagerDelegate&gt;</code></li>
<li>Specify a CLLocationManager property by adding <code>@property (strong, nonatomic) CLLocationManager *locationManager</code> right before the <code>@end</code> statement.</li>
</ol>
<p>Your App Delegate header file should now look similar to the following:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &amp;lt;UIKit/UIKit.h&amp;gt;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//Add Location Framework</span>
<span style="color: #6e371a;">#import &amp;lt;CoreLocation/CoreLocation.h&amp;gt;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//Specify this app delegate complies with the location manager delegate</span>
<span style="color: #a61390;">@interface</span> CFAAppDelegate <span style="color: #002200;">:</span> UIResponder <span style="color: #002200;">&amp;</span>lt;UIApplicationDelegate, CLLocationManagerDelegate<span style="color: #002200;">&amp;</span>gt;
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>strong, nonatomic<span style="color: #002200;">&#41;</span> UIWindow <span style="color: #002200;">*</span>window;
&nbsp;
<span style="color: #11740a; font-style: italic;">//Add a location manager property to this app delegate</span>
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>strong, nonatomic<span style="color: #002200;">&#41;</span> CLLocationManager <span style="color: #002200;">*</span>locationManager;
&nbsp;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<h2>Creating The Location Manager Object</h2>
<p>Switch over to the App Delegate implementation file (.m), and we are going to create our location manager object. The first thing we should do, since we created it as a property of our app delegate, is synthesize the property so add <code>@synthesize locationManager=_locationManager;</code> under the line that reads <code>@synthesize window = _window;</code>.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;CFAAppDelegate.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> CFAAppDelegate
&nbsp;
<span style="color: #a61390;">@synthesize</span> window <span style="color: #002200;">=</span> _window;
<span style="color: #a61390;">@synthesize</span> locationManager<span style="color: #002200;">=</span>_locationManager;</pre></td></tr></table></div>

<p>Now that our property is synthesized, we can create the object. I usually create it in the method <code>application didFinishLaunchingWithOptions:</code>. A Location Manager object is created similar to any other object but there are three important properties you should set after you have alloc&#8217;d/init&#8217;d.</p>
<ol>
<li><strong>.purpose</strong> &#8211; The purpose property is displayed to the user of your app when they are prompted to allow your app to use their location. It gives you a chance to explain what your app is going to do with their location information.</li>
<li><strong>.desiredAccuracy</strong> &#8211; The desired accuracy property allows you to tell the device how accurate you would like the location information to be. This should be set based on your application&#8217;s needs. Don&#8217;t set this property to <code>kCLLocationAccuracyBest</code> if you only need to know what city they are in. <em>NOTE: This is the &#8220;desired&#8221; accuracy, it is not guaranteed. The device will determine the best available information and provide it to you but you are not, however, guaranteed any level of accuracy.</em></li>
<li><strong>.distanceFilter</strong> &#8211; The distance filter property tells the location manager how far a device needs to move (horizontally vs. an altitude change) before triggering a new location event. It is measured in meters. You can set the property to <code>kCLDistanceFilterNone</code> to be notified of all events (this is also the default value).</li>
</ol>
<p>The completed creation of our location manage looks like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>application<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application didFinishLaunchingWithOptions<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>launchOptions
<span style="color: #002200;">&#123;</span>
    self.window <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIWindow alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> bounds<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// Override point for customization after application launch.</span>
    self.window.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor whiteColor<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>self.window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>self.locationManager<span style="color: #002200;">==</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
        _locationManager<span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CLLocationManager alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
        <span style="color: #11740a; font-style: italic;">//I'm using ARC with this project so no need to release</span>
&nbsp;
        _locationManager.delegate<span style="color: #002200;">=</span>self;
        _locationManager.purpose <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;We will try to tell you where you are if you get lost&quot;</span>;
        _locationManager.desiredAccuracy<span style="color: #002200;">=</span>kCLLocationAccuracyBest;
        _locationManager.distanceFilter<span style="color: #002200;">=</span><span style="color: #2400d9;">500</span>;
        self.locationManager<span style="color: #002200;">=</span>_locationManager;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>If you run this now, you should not notice any change in the way your application runs, you also won&#8217;t start receiving location information just yet. That comes next&#8230;</p>
<h2>Starting Location Services</h2>
<p>Now that we have our location manager configured, we want to start getting the location. To start the standard location service, you should first check to make sure that location services are enabled. This is done with a simple call to <code>[CLLocationManager locationServicesEnabled]</code> so after we set up our location manager above and before the <code>return YES;</code>, add the following code:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;">    <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>CLLocationManager locationServicesEnabled<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>self.locationManager startUpdatingLocation<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<blockquote><p>NOTE: If location services are not enabled and you start updating location services, the user will be prompted to enable location services. This could be annoying to the end user if they have to answer &#8220;No&#8221; every time your app launches.</p></blockquote>
<p>If you run your app now, you will notice that the user is prompted to enable location services (and it will include the message from the <code>.prompt</code> property of our location manager object).</p>
<div class="thumbnail" align="center"><a href="http://skitch.com/shawnegrimes/86idb/enablelocationservicesprompt"><img src="http://img.skitch.com/20120605-ke3m4ipx1cj2p9pprstkcdcrdn.preview.jpg" alt="EnableLocationServicesPrompt" /></a></div>
<h2>Receiving Location Changes</h2>
<p>We&#8217;ve started location services, but now we need to start receiving updates to location changes. This is all done through the <code>CLLocationManagerDelegate</code> protocol. There are a number of available methods to implement for this delegate but the three most important are probably:</p>
<ol>
<li>– locationManager:didUpdateToLocation:fromLocation:</li>
<li>– locationManager:didFailWithError:</li>
<li>– locationManager:didChangeAuthorizationStatus:</li>
</ol>
<h2>– locationManager:didUpdateToLocation:fromLocation:</h2>
<p>Let&#8217;s start with receiving an update in location and how to handle that. In our App Delegate implementation file (.m), add the following method placeholder below the <code>@synthesize …</code> statements and above <code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions</code> method:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>locationManager<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CLLocationManager <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>manager didUpdateToLocation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CLLocation <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>newLocation fromLocation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CLLocation <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>oldLocation<span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>One of the first things I like to do is check the timestamp of the newLocation detected. When you first start updating location services, the location manager will receive the last known location of the device, this could be hours or days old depending on the last time location services were used. In my apps, I like to make sure that I have a recent location. This following code will only use a location that has been found in the last 15.0 seconds:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;">    <span style="color: #400080;">NSDate</span><span style="color: #002200;">*</span> eventDate <span style="color: #002200;">=</span> newLocation.timestamp;
    NSTimeInterval howRecent <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>eventDate timeIntervalSinceNow<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">abs</span><span style="color: #002200;">&#40;</span>howRecent<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&amp;</span>lt; <span style="color: #2400d9;">15.0</span><span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">//Location timestamp is within the last 15.0 seconds, let's use it!</span>
    <span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>The next check that I like to perform is to see how accurate the newLocation is. This can be done by looking at the <code>.horizontalAccuracy</code> property. This property tells you how accurate your location information is. As I stated above, you can request to have very accurate locations but you are not guaranteed it. In the illustration below, the newLocation.coordinate is the location the device thinks it is, but in truth the orange circle of the .horizontalAccuracy says that it could be anywhere in that circle.</p>
<div class="thumbnail" align="center"><a href="https://skitch.com/shawnegrimes/86kp3/horizontalaccuracy"><img src="https://img.skitch.com/20120603-enfpceaw8jgsqw1hieenx48jmj.preview.jpg" alt="horizontalAccuracy" /></a></div>
<p>Your application&#8217;s need will determine how accurate of a location you need. Again, if you just need the city the user is in, you won&#8217;t need it to be as accurate as if you were trying to find something within walking distance. In the code below, I have set my accuracy threshold to 35.0 meters. This is pretty broad but I have found that it works well indoors as well as out. Insert the following code right after the comment <code>//Location timestamp is within the last 15.0 seconds, let's use it!</code></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;">        <span style="color: #11740a; font-style: italic;">//Location timestamp is within the last 15.0 seconds, let's use it!</span>
        <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>newLocation.horizontalAccuracy<span style="color: #002200;">&amp;</span>lt;<span style="color: #2400d9;">35.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
            <span style="color: #11740a; font-style: italic;">//Location seems pretty accurate, let's use it!</span>
            NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;latitude %+.6f, longitude %+.6f<span style="color: #2400d9;">\n</span>&quot;</span>,
                  newLocation.coordinate.latitude,
                  newLocation.coordinate.longitude<span style="color: #002200;">&#41;</span>;
            NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Horizontal Accuracy:%f&quot;</span>, newLocation.horizontalAccuracy<span style="color: #002200;">&#41;</span>;
&nbsp;
            <span style="color: #11740a; font-style: italic;">//Optional: turn off location services once we've gotten a good location</span>
            <span style="color: #002200;">&#91;</span>manager stopUpdatingLocation<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>The code above will print the new location to the console and then turn off location services. This is an optional step but if you don&#8217;t need location services anymore, it&#8217;s a smart thing to turn them off to conserve your user&#8217;s battery.</p>
<p>This is what our complete delegate method looks like:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>locationManager<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CLLocationManager <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>manager didUpdateToLocation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CLLocation <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>newLocation fromLocation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CLLocation <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>oldLocation<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSDate</span><span style="color: #002200;">*</span> eventDate <span style="color: #002200;">=</span> newLocation.timestamp;
    NSTimeInterval howRecent <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>eventDate timeIntervalSinceNow<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">abs</span><span style="color: #002200;">&#40;</span>howRecent<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&amp;</span>lt; <span style="color: #2400d9;">15.0</span><span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        <span style="color: #11740a; font-style: italic;">//Location timestamp is within the last 15.0 seconds, let's use it!</span>
        <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>newLocation.horizontalAccuracy<span style="color: #002200;">&amp;</span>lt;<span style="color: #2400d9;">35.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
            <span style="color: #11740a; font-style: italic;">//Location seems pretty accurate, let's use it!</span>
            NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;latitude %+.6f, longitude %+.6f<span style="color: #2400d9;">\n</span>&quot;</span>,
                  newLocation.coordinate.latitude,
                  newLocation.coordinate.longitude<span style="color: #002200;">&#41;</span>;
            NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Horizontal Accuracy:%f&quot;</span>, newLocation.horizontalAccuracy<span style="color: #002200;">&#41;</span>;
&nbsp;
            <span style="color: #11740a; font-style: italic;">//Optional: turn off location services once we've gotten a good location</span>
            <span style="color: #002200;">&#91;</span>manager stopUpdatingLocation<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Now we can run the project again. If you didn&#8217;t authorize the app to use location services before, go ahead and do that now. We haven&#8217;t done anything with the location at this point except print it out to the console. If you don&#8217;t know how to see the console, make sure Xcode is the active window (NOT the simulator) and press ⌘⇧C</p>
<p>If you are running the project on the simulator and not a device, you may not see any results in the console window. This is because the simulator does not have location services turned on by default. You can simulate a location by selecting the location services simulation in the console window:</p>
<div class="thumbnail" align="center"><a href="http://skitch.com/shawnegrimes/86typ/simulate-location"><img src="http://img.skitch.com/20120604-b359j7crjba8wctd1gje5kk112.preview.jpg" alt="Simulate Location" /></a></div>
<p>You can also simulate a location in the Simulator by using the Debug menu.</p>
<div class="thumbnail" align="center"><a href="https://skitch.com/shawnegrimes/86tn4/simulator-location-services"><img src="https://img.skitch.com/20120604-qxs23ikjy6qufjpwpg72fuewk9.preview.jpg" alt="Simulator Location Services" /></a></div>
<p>Once a location has been selected, you may need to restart the app to get the new location to show in the console window:</p>
<div class="thumbnail" align="center"><a href="https://skitch.com/shawnegrimes/86trw/location-in-console"><img src="https://img.skitch.com/20120604-ddt5unstdmea3i58ddxsgfgih8.preview.jpg" alt="Location In Console" /></a></div>
<p>Because we built the location manager into the App Delegate, you can access the device&#8217;s current location anywhere in your code by including the AppDelegate header file (.h) in your view controller&#8217;s implementation file (.m):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;CFAAppDelegate.h&quot;</span></pre></td></tr></table></div>

<p>Then whenever you need to access the location, you can use the following bit of code:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//Make sure location services are enabled before requesting the location</span>
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>CLLocationManager locationServicesEnabled<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
&nbsp;
    CFAAppDelegate <span style="color: #002200;">*</span>appDelegate<span style="color: #002200;">=</span><span style="color: #002200;">&#40;</span>CFAAppDelegate <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span>.delegate;
    CLLocation <span style="color: #002200;">*</span>currentLocation<span style="color: #002200;">=</span>appDelegate.locationManager.location;
&nbsp;
    <span style="color: #11740a; font-style: italic;">//Do what you want with the location...</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<blockquote><p><strong>About: Shawn Grimes</strong><br />
Shawn is a mobile app developer for <a href="http://elctech.com/">ELC Technologies</a>. He is a co-author of the book, <a href="http://www.amazon.com/gp/product/1430240059/ref=as_li_ss_tl?ie=UTF8&amp;tag=charmtrave-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1430240059">iOS 5 Recipes: A Problem-Solution Approach (Recipes Apress)</a>. You can follow him on twitter <a href="https://twitter.com/#!/shawng">@shawng</a>. Shawn also works with high school students to teach them app development skills through the <a href="http://www.appliedclub.org">APPlied Club</a> Program.</p></blockquote>
<p>UIKit/UIKit.hp</p>
]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2012/06/04/how-to-add-gps-to-your-ios-app-part-1/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Adding Local Weather Conditions To Your App (Part 1/2: Implementing CoreLocation)</title>
		<link>http://icodeblog.com/2010/09/03/adding-local-weather-conditions-to-your-app-part-12-implementing-corelocation/</link>
		<comments>http://icodeblog.com/2010/09/03/adding-local-weather-conditions-to-your-app-part-12-implementing-corelocation/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 22:45:12 +0000</pubDate>
		<dc:creator><![CDATA[Matt Tuzzolo]]></dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Coordinates]]></category>
		<category><![CDATA[CoreLocation]]></category>
		<category><![CDATA[GPS]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[Latitude]]></category>
		<category><![CDATA[Longitude]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=2228</guid>
		<description><![CDATA[Knowing the latitude and longitude of your users can open up all kinds of possibilities in your apps.  In an upcoming post, we&#8217;ll be discussing how you can use your user&#8217;s location to determine their local weather conditions and forecast.  But for now, we&#8217;re going to focus on Part 1 of this two part tutorial: CoreLocation.
Apple&#8217;s done a great job of abstracting GPS, Cellular Triangulation, and Wifi Access Point location lookups into CoreLocation; making it extremely easy to  ...]]></description>
				<content:encoded><![CDATA[<p>Knowing the latitude and longitude of your users can open up all kinds of possibilities in your apps.  In an upcoming post, we&#8217;ll be discussing how you can use your user&#8217;s location to determine their local weather conditions and forecast.  But for now, we&#8217;re going to focus on Part 1 of this two part tutorial: CoreLocation.</p>
<p>Apple&#8217;s done a great job of abstracting GPS, Cellular Triangulation, and Wifi Access Point location lookups into CoreLocation; making it extremely easy to determine the approximate location of your user regardless of their device and network connectivity.  Additionally, Apple&#8217;s new iPhone Simulator finally supports CoreLocation as well.  This significantly eases the process of testing your location code.</p>
<p>The first thing you&#8217;ll need to do is add the CoreLocation framework to your project.  This is pretty straightforward.  Command-Click on &#8216;Frameworks&#8217; -&gt; Add -&gt; Existing Frameworks</p>
<p><a href="/wp-content/uploads/2010/09/Screen-shot-2010-09-03-at-12.00.35-PM1.png"><img class="alignnone size-medium wp-image-2232" title="Screen shot 2010-09-03 at 12.00.35 PM" src="/wp-content/uploads/2010/09/Screen-shot-2010-09-03-at-12.00.35-PM-300x193.png" alt="" width="300" height="193" /></a></p>
<p>Select &#8216;CoreLocation.framework&#8217; and click &#8216;add&#8217;.</p>
<p><a href="/wp-content/uploads/2010/09/Screen-shot-2010-09-03-at-12.00.49-PM1.png"><img class="alignnone size-medium wp-image-2231" title="Screen shot 2010-09-03 at 12.00.49 PM" src="/wp-content/uploads/2010/09/Screen-shot-2010-09-03-at-12.00.49-PM-191x300.png" alt="" width="191" height="300" /></a></p>
<p>The class below implements the LocationManager delegate methods required to get the user&#8217;s location.  You can just as easily implement the LocationManagerDelegate protocol in your AppDelegate or elsewhere in your App.  Though I&#8217;ve found that having this class makes it super easy to drop in location support into new projects instead of having to cut/paste delegate methods (ugly).  Anyway.  Take a look:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  LocationGetter.h</span>
<span style="color: #11740a; font-style: italic;">//  CoreLocationExample</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Matt on 9/3/10.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 iCodeBlog. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &lt;uikit/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &lt;coreLocation/CoreLocation.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@protocol</span> LocationGetterDelegate
@required
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> newPhysicalLocation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CLLocation <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>location;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@interface</span> LocationGetter <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span>  <span style="color: #002200;">&#123;</span>
    CLLocationManager <span style="color: #002200;">*</span>locationManager;
    <span style="color: #a61390;">id</span> delegate;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>startUpdates;
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> CLLocationManager <span style="color: #002200;">*</span>locationManager;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic , retain<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">id</span> delegate;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<p>Notice that we&#8217;re defining our own protocol with a method that takes the new CLLocation as a parameter.  We&#8217;ll be implementing that delegate method in a minute.  Now for the class</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;">&nbsp;</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//  LocationGetter.m</span>
<span style="color: #11740a; font-style: italic;">//  CoreLocationExample</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Matt on 9/3/10.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright 2009 iCodeBlog. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &quot;LocationGetter.h&quot;</span>
<span style="color: #6e371a;">#import &lt;coreLocation/CoreLocation.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> LocationGetter
&nbsp;
<span style="color: #a61390;">@synthesize</span> locationManager, delegate;
<span style="color: #a61390;">BOOL</span> didUpdate <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>startUpdates
<span style="color: #002200;">&#123;</span>
    NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Starting Location Updates&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>locationManager <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>
        locationManager <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CLLocationManager alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
    locationManager.delegate <span style="color: #002200;">=</span> self;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// locationManager.distanceFilter = 1000;  // update is triggered after device travels this far (meters)</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Alternatively you can use kCLLocationAccuracyHundredMeters or kCLLocationAccuracyHundredMeters, though higher accuracy takes longer to resolve</span>
    locationManager.desiredAccuracy <span style="color: #002200;">=</span> kCLLocationAccuracyKilometer;
    <span style="color: #002200;">&#91;</span>locationManager startUpdatingLocation<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>locationManager<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CLLocationManager <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>manager didFailWithError<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>error
<span style="color: #002200;">&#123;</span>
    UIAlertView <span style="color: #002200;">*</span>alert <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAlertView alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Error&quot;</span> message<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Your location could not be determined.&quot;</span> delegate<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;OK&quot;</span> otherButtonTitles<span style="color: #002200;">:</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>alert show<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>alert release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">// Delegate method from the CLLocationManagerDelegate protocol.</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>locationManager<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CLLocationManager <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>manage didUpdateToLocation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CLLocation <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>newLocation fromLocation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CLLocation <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>oldLocation
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>didUpdate<span style="color: #002200;">&#41;</span>
        <span style="color: #a61390;">return</span>;
&nbsp;
    didUpdate <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
    <span style="color: #11740a; font-style: italic;">// Disable future updates to save power.</span>
    <span style="color: #002200;">&#91;</span>locationManager stopUpdatingLocation<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// let our delegate know we're done</span>
    <span style="color: #002200;">&#91;</span>delegate newPhysicalLocation<span style="color: #002200;">:</span>newLocation<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc
<span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>locationManager release<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<p>CoreLocation gives you a few options for the accuracy of the user&#8217;s location.  The more accurate the measurement, typically the longer it takes LocationManager to call it&#8217;s delegate method didUpdateToLocation.  It&#8217;s just something to keep in mind when deciding what level of accuracy to use.</p>
<p>Next we need to actually invoke this code and start getting location updates.  I usually do this in my AppDelegate&#8217;s didFinishLaunchingWithOptions, though you could also do it in viewDidLoad somewhere if you didn&#8217;t need to know the user&#8217;s location on app startup.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"> <span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>application<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application didFinishLaunchingWithOptions<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>launchOptions <span style="color: #002200;">&#123;</span>
&nbsp;
    UIActivityIndicatorView <span style="color: #002200;">*</span>spinner <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIActivityIndicatorView alloc<span style="color: #002200;">&#93;</span> initWithActivityIndicatorStyle<span style="color: #002200;">:</span>UIActivityIndicatorViewStyleWhiteLarge<span style="color: #002200;">&#93;</span>;
	spinner.center <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span>self.viewController.view.frame.size.width <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span>, self.viewController.view.frame.size.height <span style="color: #002200;">/</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#91;</span>spinner startAnimating<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>viewController.view addSubview<span style="color: #002200;">:</span>spinner<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// get our physical location</span>
    LocationGetter <span style="color: #002200;">*</span>locationGetter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>LocationGetter alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
    locationGetter.delegate <span style="color: #002200;">=</span> self;
    <span style="color: #002200;">&#91;</span>locationGetter startUpdates<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Add the view controller's view to the window and display.</span>
    <span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span>viewController.view<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>window makeKeyAndVisible<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Notice that I&#8217;ve set locationGetter&#8217;s delegate to self.  So in your .h, make sure to add LocationGetterDelegate to the interface.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  CoreLocationExampleAppDelegate.h</span>
<span style="color: #11740a; font-style: italic;">//  CoreLocationExample</span>
<span style="color: #11740a; font-style: italic;">//</span>
<span style="color: #11740a; font-style: italic;">//  Created by Matt Tuzzolo on 9/3/10.</span>
<span style="color: #11740a; font-style: italic;">//  Copyright iCodeBlog 2010. All rights reserved.</span>
<span style="color: #11740a; font-style: italic;">//</span>
&nbsp;
<span style="color: #6e371a;">#import &lt;uikit/UIKit.h&gt;</span>
<span style="color: #6e371a;">#import &quot;LocationGetter.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@class</span> CoreLocationExampleViewController;
&nbsp;
<span style="color: #a61390;">@interface</span> CoreLocationExampleAppDelegate <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span>  <span style="color: #002200;">&#123;</span>
    UIWindow <span style="color: #002200;">*</span>window;
    CoreLocationExampleViewController <span style="color: #002200;">*</span>viewController;
    CLLocation <span style="color: #002200;">*</span>lastKnownLocation;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIWindow <span style="color: #002200;">*</span>window;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet CoreLocationExampleViewController <span style="color: #002200;">*</span>viewController;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> CLLocation <span style="color: #002200;">*</span>lastKnownLocation;
&nbsp;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<p>I&#8217;ve also added a CLLocation *lastKnownLocation that we&#8217;ll use in our delegate method (which comes next):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;"># pragma mark -</span>
<span style="color: #6e371a;"># pragma mark LocationGetter Delegate Methods</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>newPhysicalLocation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CLLocation <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>location <span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Store for later use</span>
    self.lastKnownLocation <span style="color: #002200;">=</span> location;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Remove spinner from view</span>
    <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>UIView <span style="color: #002200;">*</span>v <span style="color: #a61390;">in</span> <span style="color: #002200;">&#91;</span>self.viewController.view subviews<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>v class<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #002200;">&#91;</span>UIActivityIndicatorView class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
        <span style="color: #002200;">&#123;</span>
            <span style="color: #002200;">&#91;</span>v removeFromSuperview<span style="color: #002200;">&#93;</span>;
            <span style="color: #a61390;">break</span>;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Alert user</span>
    UIAlertView <span style="color: #002200;">*</span>alert <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAlertView alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Location Found&quot;</span> message<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Found physical location.  %f %f&quot;</span>, self.lastKnownLocation.coordinate.latitude, self.lastKnownLocation.coordinate.longitude<span style="color: #002200;">&#93;</span> delegate<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;OK&quot;</span> otherButtonTitles<span style="color: #002200;">:</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>alert show<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>alert release<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// ... continue with initialization of your app</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>This last piece takes care of storing the location, removing the spinner, and firing off an alert.  If this was your code, you&#8217;d probably want to re-enable any UI elements that you&#8217;ve disabled and let the user start using your app.</p>
<p>Now build and run your app and you should see:</p>
<p><a href="/wp-content/uploads/2010/09/Screen-shot-2010-09-07-at-9.45.33-AM1.png"><img src="/wp-content/uploads/2010/09/Screen-shot-2010-09-07-at-9.45.33-AM1.png" alt="" title="Screen shot 2010-09-07 at 9.45.33 AM" width="280" height="516" class="alignnone size-full wp-image-2307" /></a></p>
<p>That&#8217;s it!</p>
<p>Here&#8217;s the <a href="/wp-content/uploads/2010/09/CoreLocationExample1.zip">Example Project</a> for the post.</p>
<p>For those of you who don&#8217;t know me yet, my name is Matt Tuzzolo (<a href="http://www.twitter.com/matt_tuzzolo">@matt_tuzzolo</a>).  This is my first iCodeBlog post.  I hope you enjoyed it.</p>
]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2010/09/03/adding-local-weather-conditions-to-your-app-part-12-implementing-corelocation/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
	</channel>
</rss>
