私はいくつかのチュートリアルに従って、私のひどいコードを混ぜる。今私は私の現在の場所を得ることができます。ボタンをタップすると、現在の位置にあるピンがトリガーされます。ピンをタップすると、メッセージに自分の現在のアドレスが表示されます。現在のユーザーの住所のアドレスを取得
私は2つの質問があります:私は、より正確なアドレスを取得できないのはなぜ
を?今、私は国、都市、地区の住所を受け取りますが、道路の名前はありません。
現在の場所の住所の「テキスト」を取得するにはどうすればよいですか? UILabelにアドレスを表示したいのですが、その方法はわかりません。
ありがとうございました!ここ
が.hのここ
#import <UIKit/UIKit.h>
#import "MapKit/MapKit.h"
#import "CoreLocation/CoreLocation.h"
@interface UserLocationAddressViewController : UIViewController <MKMapViewDelegate,MKReverseGeocoderDelegate>
{
MKMapView *userLocationAddMapView;
CLLocationManager *locationManager;
}
@property (nonatomic, retain) MKMapView *userLocationAddMapView;
-(IBAction)getUserLocationAddress:(id)sender;
@end
とは.Mだ
#import "UserLocationAddressViewController.h"
@implementation UserLocationAddressViewController
@synthesize userLocationAddMapView;
-(IBAction)getUserLocationAddress:(id)sender
{
MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:locationManager.location.coordinate];
geoCoder.delegate = self;
[geoCoder start];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(void)dealloc
{
[userLocationAddMapView release];
[super dealloc];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.userLocationAddMapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
userLocationAddMapView.showsUserLocation = YES;
userLocationAddMapView.delegate = self;
self.userLocationAddMapView.mapType = MKMapTypeStandard;
locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
CLLocationCoordinate2D coordinate = locationManager.location.coordinate;
MKCoordinateRegion mapRegion;
mapRegion.center = coordinate;
MKCoordinateSpan mapSpan;
mapSpan.latitudeDelta = 0.006;
mapSpan.longitudeDelta = 0.006;
mapRegion.span = mapSpan;
[userLocationAddMapView setRegion:mapRegion animated:YES];
self.userLocationAddMapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.userLocationAddMapView];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Get Add" style:UIBarButtonItemStylePlain target:self action:@selector(getUserLocationAddress:)] autorelease];
}
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
NSLog(@"placemark %f %f", placemark.coordinate.latitude, placemark.coordinate.longitude);
NSLog(@"addressDictionary %@", placemark.addressDictionary);
[userLocationAddMapView addAnnotations:[NSArray arrayWithObjects:placemark, nil]];
[geocoder release];
}
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
NSLog(@"reverseGeocoder fail");
[geocoder release];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
これはCLGeocoder提案のためのiOS 5 – Rob
MK_CLASS_DEPRECATED(NA、NA、3_0、5_0) – VietHung