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!