現在、残りの課題を完了する前に、地図上のピンに注釈を付けるという概念をテストしようとしています。割り当ての指示では、CLLocationManager は不要であると記載されています。これまでのところ、MKanotate クラスの特定のインスタンスで mkAnnotate ピンを呼び出してみました。デリゲート メソッドを呼び出してみましたが、手動で座標を入力しようとしましたが成功しませんでした。割り当ての後半で、セグメント化されたボタンの選択に基づいて、プログラムがピンをドロップして場所にズームするようにしたいのですが、今はピンをドロップする方法を理解したいだけです。ここに私のViewContoller.mファイルのコードがあります
#import "GoThereViewController.h"
@interface GoThereViewController ()
@end
@implementation GoThereViewController
//@synthesize segment;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[world setShowsUserLocation:YES];
//Location array declarations
//GoThereMapPoint *gtET = [[GoThereMapPoint alloc]initWithCoordinate:CLLocationCoordinate2DMake(39.774033,-86.172754) title:@"Engineering & Technology Building"];
GoThereMapPoint *gtEmpireState = [[GoThereMapPoint alloc]initWithCoordinate:CLLocationCoordinate2DMake(40.7483786347046,-73.98555994033813) title:@"Empire State Building"];
GoThereMapPoint *gtTajMahal = [[GoThereMapPoint alloc]initWithCoordinate:CLLocationCoordinate2DMake(27.171171855453526,78.04248690605164) title:@"Taj Mahal"];
//Put in array.
//aryGoThere = [NSArray arrayWithObjects:gtET,gtEmpireState,gtTajMahal, nil];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
//Somehow this method calls the annotate and zoom method
-(void)didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
GoThereMapPoint *gtET = [[GoThereMapPoint alloc]initWithCoordinate:CLLocationCoordinate2DMake(39.774033,-86.172754) title:@"Engineering & Technology Building"];
[self foundLocation:newLocation];
}
//Create instance of location and zoom to it
-(void)foundLocation:(CLLocation *)loc
{
//Create instance of location
CLLocationCoordinate2D coord = [loc coordinate];
//Add pin
GoThereMapPoint *mp = [[GoThereMapPoint alloc]initWithCoordinate:coord title:@"test"];
[world addAnnotation:mp]; //Zoom to location
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord,500,500);
[world setRegion:region animated:YES];
}
他にご不明な点がございましたら、お気軽にお問い合わせください。
編集: MKAnnotate クラスの名前が GoThereViewController であることを忘れていました。