forked from myell0w/MTLocation
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Commit of MTLocateMeBarButtonItem
- Loading branch information
0 parents
commit 6b9a9aa
Showing
17 changed files
with
831 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
Copyright (c) 2009-2010, Matthias Tretter | |||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,37 @@ | |||
// | |||
// MTLocateMeBarButtonItem.h | |||
// | |||
// Created by Matthias Tretter on 21.01.11. | |||
// Copyright (c) 2009-2011 Matthias Tretter, @myell0w. All rights reserved. | |||
// | |||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | |||
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |||
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
|
|||
#import <Foundation/Foundation.h> | |||
#import <CoreLocation/CoreLocation.h> | |||
#import "MTLocationDefines.h" | |||
|
|||
@class MTLocateMeButton; | |||
|
|||
|
|||
@interface MTLocateMeBarButtonItem : UIBarButtonItem <CLLocationManagerDelegate> { | |||
MTLocateMeButton *locateMeButton_; | |||
BOOL headingEnabled_; | |||
} | |||
|
|||
@property (nonatomic, assign) MTLocationStatus locationStatus; | |||
@property (nonatomic, assign) BOOL headingEnabled; | |||
|
|||
|
|||
- (id)initWithLocationStatus:(MTLocationStatus)locationStatus; | |||
// if you pass in a locationManager the button acts as it's delegate and sends Notifications when location changes | |||
- (id)initWithLocationStatus:(MTLocationStatus)locationStatus locationManager:(CLLocationManager *)locationManager; | |||
|
|||
- (void)setLocationStatus:(MTLocationStatus)locationStatus animated:(BOOL)animated; | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,158 @@ | |||
// | |||
// MTLocateMeBarButtonItem.m | |||
// | |||
// Created by Matthias Tretter on 21.01.11. | |||
// Copyright (c) 2009-2011 Matthias Tretter, @myell0w. All rights reserved. | |||
// | |||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | |||
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |||
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
|
|||
#import "MTLocateMeBarButtonItem.h" | |||
#import "MTLocateMeButton.h" | |||
|
|||
//////////////////////////////////////////////////////////////////////// | |||
#pragma mark - | |||
#pragma mark Defines/Customization | |||
//////////////////////////////////////////////////////////////////////// | |||
|
|||
|
|||
#define kLocateMeButtonFrame CGRectMake(0.0f, 0.0f, 33.0f, 32.0f) | |||
|
|||
|
|||
//////////////////////////////////////////////////////////////////////// | |||
#pragma mark - | |||
#pragma mark Private Class Extension | |||
//////////////////////////////////////////////////////////////////////// | |||
|
|||
@interface MTLocateMeBarButtonItem () | |||
|
|||
@property (nonatomic, retain) MTLocateMeButton *locateMeButton; | |||
|
|||
@end | |||
|
|||
|
|||
@implementation MTLocateMeBarButtonItem | |||
|
|||
@synthesize locateMeButton = locateMeButton_; | |||
@synthesize headingEnabled = headingEnabled_; | |||
|
|||
//////////////////////////////////////////////////////////////////////// | |||
#pragma mark - | |||
#pragma mark Lifecycle, Memory Management | |||
//////////////////////////////////////////////////////////////////////// | |||
|
|||
// the designated initializer | |||
- (id)initWithLocationStatus:(MTLocationStatus)locationStatus locationManager:(CLLocationManager *)locationManager { | |||
locateMeButton_ = [[MTLocateMeButton alloc] initWithFrame:kLocateMeButtonFrame]; | |||
|
|||
if ((self = [super initWithCustomView:locateMeButton_])) { | |||
locateMeButton_.locationStatus = locationStatus; | |||
headingEnabled_ = YES; | |||
|
|||
if (locationManager != nil) { | |||
locationManager.delegate = self; | |||
} | |||
} | |||
|
|||
return self; | |||
} | |||
|
|||
- (id)initWithLocationStatus:(MTLocationStatus)locationStatus { | |||
return [self initWithLocationStatus:locationStatus locationManager:nil]; | |||
} | |||
|
|||
// The designated initializer of the base-class | |||
- (id)initWithCustomView:(UIView *)customView { | |||
return [self initWithLocationStatus:MTLocationStatusIdle]; | |||
} | |||
|
|||
- (void)dealloc { | |||
[locateMeButton_ release], locateMeButton_ = nil; | |||
|
|||
[super dealloc]; | |||
} | |||
|
|||
//////////////////////////////////////////////////////////////////////// | |||
#pragma mark - | |||
#pragma mark Setter/Getter | |||
//////////////////////////////////////////////////////////////////////// | |||
|
|||
- (void)setLocationStatus:(MTLocationStatus)locationStatus { | |||
[self setLocationStatus:locationStatus animated:NO]; | |||
} | |||
|
|||
- (void)setLocationStatus:(MTLocationStatus)locationStatus animated:(BOOL)animated { | |||
[self.locateMeButton setLocationStatus:locationStatus animated:YES]; | |||
} | |||
|
|||
- (MTLocationStatus)locationStatus { | |||
return self.locateMeButton.locationStatus; | |||
} | |||
|
|||
//////////////////////////////////////////////////////////////////////// | |||
#pragma mark - | |||
#pragma mark locationManager Delegate | |||
//////////////////////////////////////////////////////////////////////// | |||
|
|||
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { | |||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: manager, @"locationManager", | |||
newLocation, @"newLocation", | |||
oldLocation, @"oldLocation", nil]; | |||
|
|||
[[NSNotificationCenter defaultCenter] postNotificationName:kMTLocationManagerDidUpdateToLocationFromLocation object:self userInfo:userInfo]; | |||
} | |||
|
|||
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { | |||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: manager, @"locationManager", | |||
error, @"error", nil]; | |||
|
|||
[[NSNotificationCenter defaultCenter] postNotificationName:kMTLocationManagerDidFailWithError object:self userInfo:userInfo]; | |||
} | |||
|
|||
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading { | |||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: manager, @"locationManager", | |||
newHeading, @"newHeading", nil]; | |||
|
|||
[[NSNotificationCenter defaultCenter] postNotificationName:kMTLocationManagerDidUpdateHeading object:self userInfo:userInfo]; | |||
} | |||
|
|||
- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager { | |||
return YES; | |||
} | |||
|
|||
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { | |||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: manager, @"locationManager", | |||
region, @"region", nil]; | |||
|
|||
[[NSNotificationCenter defaultCenter] postNotificationName:kMTLocationManagerDidEnterRegion object:self userInfo:userInfo]; | |||
} | |||
|
|||
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { | |||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: manager, @"locationManager", | |||
region, @"region", nil]; | |||
|
|||
[[NSNotificationCenter defaultCenter] postNotificationName:kMTLocationManagerDidExitRegion object:self userInfo:userInfo]; | |||
} | |||
|
|||
- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error { | |||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: manager, @"locationManager", | |||
region, @"region", | |||
error, @"error", nil]; | |||
|
|||
[[NSNotificationCenter defaultCenter] postNotificationName:kMTLocationManagerMonitoringDidFailForRegion object:self userInfo:userInfo]; | |||
} | |||
|
|||
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { | |||
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: manager, @"locationManager", | |||
[NSNumber numberWithInt:status], @"status", nil]; | |||
|
|||
[[NSNotificationCenter defaultCenter] postNotificationName:kMTLocationManagerDidChangeAuthorizationStatus object:self userInfo:userInfo]; | |||
} | |||
|
|||
|
|||
@end |
Oops, something went wrong.