Skip to content

Latest commit

 

History

History
68 lines (57 loc) · 2.01 KB

README.md

File metadata and controls

68 lines (57 loc) · 2.01 KB

Hawk

A simple iOS control for picking map locations

alt tag

Installation

  • Copy the contents of the 'Source' folder to your project
  • Import MapKit.framework
  • Add the NSLocationWhenInUseUsageDescription plist key
<key>NSLocationWhenInUseUsageDescription</key>
<string>Find nearby locations</string>

Usage

.h

Import Hawk and set your view controller as the delegate

#import <UIKit/UIKit.h>
#import "HawkSearchController.h"

@interface ViewController : UIViewController <HawkDelegate>

.m

Create a new HawkSearchController and set the delegate

- (IBAction)pickLocation{
    HawkSearchController *hawk = [[HawkSearchController alloc] init];
    hawk.delegate = self;
    [self presentViewController:hawk animated:TRUE completion:nil];
}

Implement Hawk's delegate methods

- (void)didCancelMapSearch{
    NSLog(@"User cancelled picking location");
}

- (void)didSelectMapLocation:(CLPlacemark *)placemark{
    NSLog(@"User picked location");
    
    NSDictionary *addressDictionary = placemark.addressDictionary;
    locationLabel.text = [NSString stringWithFormat:@"%@, %@, %@ %@, %@",
                          [addressDictionary valueForKey:@"Street"],
                          [addressDictionary valueForKey:@"SubAdministrativeArea"],
                          [addressDictionary valueForKey:@"State"],
                          [addressDictionary valueForKey:@"ZIP"],
                          [addressDictionary valueForKey:@"CountryCode"]];
}

Customization

Optionally, you can set Hawk's title and tint color

- (IBAction)pickLocation{
    HawkSearchController *hawk = [[HawkSearchController alloc] init];
    hawk.delegate = self;
    hawk.barTitle = @"Pick A Location";
    hawk.tintColor = [UIColor redColor];
    [self presentViewController:hawk animated:TRUE completion:nil];
}

Notes

  • Hawk looks best when presented modally. Display issues may arise if inside a navigation controller.