Skip to content

Commit efa24f7

Browse files
committed
LocateMe: Version 4.0, 2014-09-17
Updated for iOS 8 SDK. Now uses storyboards. This demonstrates the two primary use cases for the Core Location Framework: getting the user's location and tracking changes to the user's location. Signed-off-by: Liu Lantao <[email protected]>
1 parent d7fae3d commit efa24f7

26 files changed

+2119
-0
lines changed

Diff for: LocateMe/LICENSE.txt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Sample code project: LocateMe
2+
Version: 4.0
3+
4+
IMPORTANT: This Apple software is supplied to you by Apple
5+
Inc. ("Apple") in consideration of your agreement to the following
6+
terms, and your use, installation, modification or redistribution of
7+
this Apple software constitutes acceptance of these terms. If you do
8+
not agree with these terms, please do not use, install, modify or
9+
redistribute this Apple software.
10+
11+
In consideration of your agreement to abide by the following terms, and
12+
subject to these terms, Apple grants you a personal, non-exclusive
13+
license, under Apple's copyrights in this original Apple software (the
14+
"Apple Software"), to use, reproduce, modify and redistribute the Apple
15+
Software, with or without modifications, in source and/or binary forms;
16+
provided that if you redistribute the Apple Software in its entirety and
17+
without modifications, you must retain this notice and the following
18+
text and disclaimers in all such redistributions of the Apple Software.
19+
Neither the name, trademarks, service marks or logos of Apple Inc. may
20+
be used to endorse or promote products derived from the Apple Software
21+
without specific prior written permission from Apple. Except as
22+
expressly stated in this notice, no other rights or licenses, express or
23+
implied, are granted by Apple herein, including but not limited to any
24+
patent rights that may be infringed by your derivative works or by other
25+
works in which the Apple Software may be incorporated.
26+
27+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
28+
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
29+
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
30+
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
31+
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
32+
33+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
34+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36+
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
37+
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
38+
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
39+
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
40+
POSSIBILITY OF SUCH DAMAGE.
41+
42+
Copyright (C) 2014 Apple Inc. All Rights Reserved.

Diff for: LocateMe/LocateMe.xcodeproj/project.pbxproj

+366
Large diffs are not rendered by default.

Diff for: LocateMe/LocateMe/AppDelegate.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Copyright (C) 2014 Apple Inc. All Rights Reserved.
3+
See LICENSE.txt for this sample’s licensing information
4+
5+
Abstract:
6+
7+
The application delegate has a minimal role in this sample: in -applicationDidFinishLaunching: it adds the tab bar controller's view to the window. It also creates a CLLocationManager object to check the locationServicesEnabled property at launch time.
8+
9+
*/
10+
11+
#import <UIKit/UIKit.h>
12+
13+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
14+
15+
@property (strong, nonatomic) UIWindow *window;
16+
17+
@end

Diff for: LocateMe/LocateMe/AppDelegate.m

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright (C) 2014 Apple Inc. All Rights Reserved.
3+
See LICENSE.txt for this sample’s licensing information
4+
5+
*/
6+
7+
#import "AppDelegate.h"
8+
#import <CoreLocation/CoreLocation.h>
9+
10+
@implementation AppDelegate
11+
12+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
13+
{
14+
if (![CLLocationManager locationServicesEnabled]) {
15+
// location services is disabled, alert user
16+
UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DisabledTitle", @"DisabledTitle")
17+
message:NSLocalizedString(@"DisabledMessage", @"DisabledMessage")
18+
delegate:nil
19+
cancelButtonTitle:NSLocalizedString(@"OKButtonTitle", @"OKButtonTitle")
20+
otherButtonTitles:nil];
21+
[servicesDisabledAlert show];
22+
}
23+
return YES;
24+
}
25+
26+
@end

Diff for: LocateMe/LocateMe/CLLocation+Strings.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright (C) 2014 Apple Inc. All Rights Reserved.
3+
See LICENSE.txt for this sample’s licensing information
4+
5+
Abstract:
6+
7+
This is an Objective C category on the CLLocation class that extends the class by adding some convenience methods for presenting localized string representations of various properties.
8+
9+
*/
10+
11+
#import <CoreLocation/CoreLocation.h>
12+
13+
@interface CLLocation (Strings)
14+
15+
- (NSString *)localizedCoordinateString;
16+
- (NSString *)localizedAltitudeString;
17+
- (NSString *)localizedHorizontalAccuracyString;
18+
- (NSString *)localizedVerticalAccuracyString;
19+
- (NSString *)localizedCourseString;
20+
- (NSString *)localizedSpeedString;
21+
22+
@end

Diff for: LocateMe/LocateMe/CLLocation+Strings.m

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright (C) 2014 Apple Inc. All Rights Reserved.
3+
See LICENSE.txt for this sample’s licensing information
4+
5+
*/
6+
7+
#import "CLLocation+Strings.h"
8+
9+
@implementation CLLocation (Strings)
10+
11+
- (NSString *)localizedCoordinateString {
12+
if (self.horizontalAccuracy < 0) {
13+
return NSLocalizedString(@"DataUnavailable", @"DataUnavailable");
14+
}
15+
NSString *latString = (self.coordinate.latitude < 0) ? NSLocalizedString(@"South", @"South") : NSLocalizedString(@"North", @"North");
16+
NSString *lonString = (self.coordinate.longitude < 0) ? NSLocalizedString(@"West", @"West") : NSLocalizedString(@"East", @"East");
17+
return [NSString stringWithFormat:NSLocalizedString(@"LatLongFormat", @"LatLongFormat"), fabs(self.coordinate.latitude), latString, fabs(self.coordinate.longitude), lonString];
18+
}
19+
20+
- (NSString *)localizedAltitudeString {
21+
if (self.verticalAccuracy < 0) {
22+
return NSLocalizedString(@"DataUnavailable", @"DataUnavailable");
23+
}
24+
NSString *seaLevelString = (self.altitude < 0) ? NSLocalizedString(@"BelowSeaLevel", @"BelowSeaLevel") : NSLocalizedString(@"AboveSeaLevel", @"AboveSeaLevel");
25+
return [NSString stringWithFormat:NSLocalizedString(@"AltitudeFormat", @"AltitudeFormat"), fabs(self.altitude), seaLevelString];
26+
}
27+
28+
- (NSString *)localizedHorizontalAccuracyString {
29+
if (self.horizontalAccuracy < 0) {
30+
return NSLocalizedString(@"DataUnavailable", @"DataUnavailable");
31+
}
32+
return [NSString stringWithFormat:NSLocalizedString(@"AccuracyFormat", @"AccuracyFormat"), self.horizontalAccuracy];
33+
}
34+
35+
- (NSString *)localizedVerticalAccuracyString {
36+
if (self.verticalAccuracy < 0) {
37+
return NSLocalizedString(@"DataUnavailable", @"DataUnavailable");
38+
}
39+
return [NSString stringWithFormat:NSLocalizedString(@"AccuracyFormat", @"AccuracyFormat"), self.verticalAccuracy];
40+
}
41+
42+
- (NSString *)localizedCourseString {
43+
if (self.course < 0) {
44+
return NSLocalizedString(@"DataUnavailable", @"DataUnavailable");
45+
}
46+
return [NSString stringWithFormat:NSLocalizedString(@"CourseFormat", @"CourseFormat"), self.course];
47+
}
48+
49+
- (NSString *)localizedSpeedString {
50+
if (self.speed < 0) {
51+
return NSLocalizedString(@"DataUnavailable", @"DataUnavailable");
52+
}
53+
return [NSString stringWithFormat:NSLocalizedString(@"SpeedFormat", @"SpeedFormat"), self.speed];
54+
}
55+
56+
@end

Diff for: LocateMe/LocateMe/GetLocationViewController.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Copyright (C) 2014 Apple Inc. All Rights Reserved.
3+
See LICENSE.txt for this sample’s licensing information
4+
5+
Abstract:
6+
7+
Attempts to acquire a location measurement with a specific level of accuracy. A timeout is used to avoid wasting power in the case where a sufficiently accurate measurement cannot be acquired. Presents a SetupViewController instance so the user can configure the desired accuracy and timeout. Uses a LocationDetailViewController instance to drill down into details for a given location measurement.
8+
9+
*/
10+
11+
#import <UIKit/UIKit.h>
12+
13+
@interface GetLocationViewController : UIViewController
14+
15+
@end

0 commit comments

Comments
 (0)