Skip to content

raaum/Hawk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A simple iOS control for picking map locations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published