Skip to content

A Framework to add convenience-stuff for easier coping with CoreLocation/MapKit on iOS. It includes a custom UIBarButtonItem mimicing the Locate-Me-Button of the built-in Google Maps App

License

Notifications You must be signed in to change notification settings

myell0w/MTLocation

Repository files navigation

Read Me

Currently Idle Currently searching for a location Currently receiving location updates Currently receiving heading updates

Description

These classes aim to mimic some of the functions of the built-in Google Maps App on iOS for you. Currently the library contains a simple Location Manager-Singleton that sends out notifications when CLLocationManager-Delegate-Methods are called and a UIBarButtonItem/UIButton that acts as a Locate-Me Button that behaves similar to the one in the Google Maps App. The switch from one mode to another is animated, just like in the Google Maps App.

It can also be customized to support Heading-Updates, by setting property headingEnabled.

Routes/Directions

If you want to display routes directly on top of MKMapView have a look at my new framework MTDirectionsKit: mtdirectionsk.it

Installation

Just copy over all .h and .m - Files to your project, as well as the image bundle included. You may exchange the images with your own, but make sure to adopt frames and sizes in the code, if your images have a different size than the one provided (only if there are any visual quirks).

Usage

Here's a minimal example of how to use MTLocation: https://gist.github.com/1373050

If you have problems getting the map-rotation to work, please refer to the following thread on StackOverflow: Rotating MapView

Update: MTLocation now provides the category-method [MKMapView sizeToFitTrackingModeFollowWithHeading] to automatically size the MapView.

You can use MTLocateMeBarButtonItem like this:

 // Configure Location Manager
 [MTLocationManager sharedInstance].locationManager.desiredAccuracy = kCLLocationAccuracyBest;
 [MTLocationManager sharedInstance].locationManager.distanceFilter = kCLDistanceFilterNone;
 [MTLocationManager sharedInstance].locationManager.headingFilter = 5; // 5 Degrees

 // Create MapView
 self.mapView = [[[MKMapView alloc] initWithFrame:CGRectZero] autorelease];
 [self.view addSubview:self.mapView];

 // create locate-me item, automatically prepare mapView
 self.locateMeItem = [UIBarButtonItem userTrackingBarButtonItemForMapView:self.mapView];
 // add target-action
 [self.locateMeItem addTarget:self action:@selector(myCustomSelector:) forControlEvents:UIControlEventTouchUpInside];
 // disable heading
 self.locateMeItem.headingEnabled = NO;
 
 // create array with ToolbarItems
 NSArray *toolbarItems = [NSArray arrayWithObject:self.locateMeItem];
 // set toolbar items
 [self.toolbar setItems:toolbarItems animated:NO];

About

A Framework to add convenience-stuff for easier coping with CoreLocation/MapKit on iOS. It includes a custom UIBarButtonItem mimicing the Locate-Me-Button of the built-in Google Maps App

Resources

License

Stars

Watchers

Forks

Packages

No packages published