Skip to content

Commit

Permalink
Subclassed MKPlacemark to allow storing of placemark coordinate
Browse files Browse the repository at this point in the history
  • Loading branch information
samvermette committed May 1, 2011
1 parent 4a01571 commit 8e8ff1d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 5 deletions.
6 changes: 4 additions & 2 deletions SVGeocoder/SVGeocoder.h
Expand Up @@ -10,6 +10,8 @@
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

#import "SVPlacemark.h"

@protocol SVGeocoderDelegate;

@interface SVGeocoder : NSObject {
Expand All @@ -20,7 +22,7 @@

- (SVGeocoder*)initWithCoordinate:(CLLocationCoordinate2D)coordinate;
- (SVGeocoder*)initWithAddress:(NSString *)address inRegion:(MKCoordinateRegion)region;
- (SVGeocoder*)initWithAddress:(NSString*)address;
- (SVGeocoder*)initWithAddress:(NSString *)address;

- (void)startAsynchronous;

Expand All @@ -29,7 +31,7 @@

@protocol SVGeocoderDelegate

- (void)geocoder:(SVGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark;
- (void)geocoder:(SVGeocoder *)geocoder didFindPlacemark:(SVPlacemark *)placemark;
- (void)geocoder:(SVGeocoder *)geocoder didFailWithError:(NSError *)error;

@end
2 changes: 1 addition & 1 deletion SVGeocoder/SVGeocoder.m
Expand Up @@ -125,7 +125,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
}
}

MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(lat, lng) addressDictionary:formattedAddressDict];
SVPlacemark *placemark = [[SVPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(lat, lng) addressDictionary:formattedAddressDict];
[formattedAddressDict release];

NSLog(@"SVGeocoder -> Found Placemark");
Expand Down
18 changes: 18 additions & 0 deletions SVGeocoder/SVPlacemark.h
@@ -0,0 +1,18 @@
//
// SVPlacemark.h
// SVGeocoder
//
// Created by Sam Vermette on 01.05.11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface SVPlacemark : MKPlacemark {

}

@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;

@end
33 changes: 33 additions & 0 deletions SVGeocoder/SVPlacemark.m
@@ -0,0 +1,33 @@
//
// SVPlacemark.m
// SVGeocoder
//
// Created by Sam Vermette on 01.05.11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SVPlacemark.h"


@implementation SVPlacemark

@synthesize coordinate;

- (id)initWithCoordinate:(CLLocationCoordinate2D)aCoordinate addressDictionary:(NSDictionary *)addressDictionary {

if(self = [super initWithCoordinate:aCoordinate addressDictionary:addressDictionary])
self.coordinate = aCoordinate;

return self;
}

- (NSString*)description {

NSDictionary *coordDict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:self.coordinate.latitude], @"latitude", [NSNumber numberWithFloat:self.coordinate.longitude], @"longitude", nil];

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:coordDict, @"coordinate", self.addressDictionary, @"address", nil];

return [dict description];
}

@end
4 changes: 2 additions & 2 deletions Sample/Classes/SVGeocoderAppViewController.m
Expand Up @@ -24,9 +24,9 @@ - (void)geocode {
[geocodeRequest startAsynchronous];
}

- (void)geocoder:(SVGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
- (void)geocoder:(SVGeocoder *)geocoder didFindPlacemark:(SVPlacemark *)placemark {

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Placemark Found!" message:[[placemark addressDictionary] description] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Placemark Found!" message:[placemark description] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
Expand Down
6 changes: 6 additions & 0 deletions Sample/SVGeocoder.xcodeproj/project.pbxproj
Expand Up @@ -14,6 +14,7 @@
220BC2ED1347FDF600D0DD26 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = 220BC2E91347FDF600D0DD26 /* CHANGELOG.md */; };
220BC2EE1347FDF600D0DD26 /* JSONKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 220BC2EB1347FDF600D0DD26 /* JSONKit.m */; };
220BC2EF1347FDF600D0DD26 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 220BC2EC1347FDF600D0DD26 /* README.md */; };
2215D386136DE916007A3351 /* SVPlacemark.m in Sources */ = {isa = PBXBuildFile; fileRef = 2215D385136DE916007A3351 /* SVPlacemark.m */; };
227829E313061C8C00CCA1B9 /* SVGeocoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 227829CB13061C8C00CCA1B9 /* SVGeocoder.m */; };
22B7DFAE1305BA170014DB40 /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22B7DFAD1305BA170014DB40 /* AddressBook.framework */; };
22B7DFEB1305BA250014DB40 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22B7DFEA1305BA250014DB40 /* MapKit.framework */; };
Expand All @@ -34,6 +35,8 @@
220BC2EA1347FDF600D0DD26 /* JSONKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSONKit.h; sourceTree = "<group>"; };
220BC2EB1347FDF600D0DD26 /* JSONKit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSONKit.m; sourceTree = "<group>"; };
220BC2EC1347FDF600D0DD26 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
2215D384136DE916007A3351 /* SVPlacemark.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVPlacemark.h; sourceTree = "<group>"; };
2215D385136DE916007A3351 /* SVPlacemark.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVPlacemark.m; sourceTree = "<group>"; };
227829CA13061C8C00CCA1B9 /* SVGeocoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGeocoder.h; sourceTree = "<group>"; };
227829CB13061C8C00CCA1B9 /* SVGeocoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVGeocoder.m; sourceTree = "<group>"; };
22B7DFAD1305BA170014DB40 /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -101,6 +104,8 @@
children = (
227829CA13061C8C00CCA1B9 /* SVGeocoder.h */,
227829CB13061C8C00CCA1B9 /* SVGeocoder.m */,
2215D384136DE916007A3351 /* SVPlacemark.h */,
2215D385136DE916007A3351 /* SVPlacemark.m */,
220BC2E81347FDF600D0DD26 /* JSONKit */,
);
name = SVGeocoder;
Expand Down Expand Up @@ -220,6 +225,7 @@
28D7ACF80DDB3853001CB0EB /* SVGeocoderAppViewController.m in Sources */,
227829E313061C8C00CCA1B9 /* SVGeocoder.m in Sources */,
220BC2EE1347FDF600D0DD26 /* JSONKit.m in Sources */,
2215D386136DE916007A3351 /* SVPlacemark.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 8e8ff1d

Please sign in to comment.