Reverse geocode coordinates to street address and setting as subtitle in annotation?
Posted
by
Krismutt
on Stack Overflow
See other posts from Stack Overflow
or by Krismutt
Published on 2010-12-29T20:51:11Z
Indexed on
2010/12/29
21:54 UTC
Read the original article
Hit count: 259
Hey everybody! Basically I wanna reverse geocode my coordinates for my annotation and show the address as the subtitle for the annotation. I just cant figure out how to do it...
savePosition.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#import <MapKit/MKReverseGeocoder.h>
#import <AddressBook/AddressBook.h>
@interface savePosition : NSObject <MKAnnotation, MKReverseGeocoderDelegate> {
CLLocationCoordinate2D coordinate;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
-(id)initWithCoordinate:(CLLocationCoordinate2D) coordinate;
- (NSString *)subtitle;
- (NSString *)title;
@end
savePosition.m
@synthesize coordinate;
-(NSString *)subtitle{
return [NSString stringWithFormat:@"%f", streetAddress];
}
-(NSString *)title{
return @"Saved position";
}
-(id)initWithCoordinate:(CLLocationCoordinate2D) coor{
coordinate=coor;
NSLog(@"%f,%f",coor.latitude,coor.longitude);
return self;
MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate];
geocoder.delegate = self;
[geocoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark
*)placemark{
NSString *streetAddress = [NSString stringWithFormat:@"%@", [placemark.addressDictionary objectForKey:kABPersonAddressStreetKey]];
}
@end
any ideas?? Thanks in advance!
© Stack Overflow or respective owner