たくさんUIViewController
のピンがすでにあるマップをロードするものがあります。MKMapView
ピンを表示するのに問題はありませんが、ユーザーが最初にmapViewに到達したときにsetRegionを実行できないようです。私は、、、、、、など、機能する可能性のあるすべての可能なメソッドにコードを入れてみましたが、役に立ちviewDidLoad
ませviewWillLoad
んでした。mapViewWillStartLoadingMap
mapViewDidFinishLoadingMap
それでも、前のviewControllerに戻ってから、mapViewを含むviewContollerに再度移動すると、指定された領域に「ズーム」されます。
私が知らないこれを行うための超秘密の方法はありますか?[mapView setRegion:(...) animated:YES];
選択した地域を表示するために地図を「ズーム」/更新するのに十分な電話をかけるべきではありませんか?
また、誰かがピン(私は私のものに使用MKPointAnnotation
しています)をアニメーション化してドロップインをアニメーション化する方法と、マップをアニメーション化してズームインする方法を知っている場合(両方をアニメーション化するように設定していますが、どちらも実行していません...) 、その情報もいただければ幸いです。
ありがとう!
コード:
@implementation FindOnMapMapView
@synthesize mapView;
@synthesize mapViewTabBarItem;
@synthesize results;
@synthesize reverseGeocoder;
- (void)viewDidLoad
{
[super viewDidLoad];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
MKCoordinateRegion mapRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake([defaults doubleForKey:@"latitude"], [defaults doubleForKey:@"longitude"]), MKCoordinateSpanMake(0.744494189288569, 0.744494189288569));
mapView.region = mapRegion;
[mapView setRegion:mapRegion animated:YES];
NSMutableArray *annotations = [[NSMutableArray alloc] init];
for(ThePlace *place in results)
{
MKPointAnnotation *addAnnotation = [[MKPointAnnotation alloc] init];
[addAnnotation setCoordinate:CLLocationCoordinate2DMake(place.latitude, place.longitude)];
addAnnotation.title = place.placename;
addAnnotation.subtitle = [NSString stringWithFormat:@"Distance: %@", place.distance];
[mapView addAnnotation:addAnnotation];
}
[self.mapView addAnnotations:annotations ];
}
- (void)viewWillAppear:(BOOL)animated
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
MKCoordinateRegion mapRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake([defaults doubleForKey:@"latitude"], [defaults doubleForKey:@"longitude"]), MKCoordinateSpanMake(0.744494189288569, 0.744494189288569));
NSLog(@"Region Coords are: Latitude:%f, Longitude:%f", [defaults doubleForKey:@"latitude"], [defaults doubleForKey:@"longitude"]);
mapView.region = mapRegion;
[mapView setRegion:mapRegion animated:YES];
}