0
現在我正試圖在我完成剩餘的作業之前測試在地圖上註釋別針的概念。分配指令說明不需要CLLocationManager。到目前爲止,我已經嘗試在我的MKannotate類的特定實例上調用mkAnnotate引腳。我曾嘗試調用委託方法,並嘗試手動輸入座標而未成功。在稍後的作業中,我想讓程序根據選擇的分段按鈕放大縮放到一個位置,但現在我只想弄清楚如何放置一個pin。在這裏是我的ViewContoller.m文件不能讓MKannotate別針在我的地圖上顯示
#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。
請參閱此鏈接:http://stackoverflow.com/questions/7022411/mkannotationview-pin-wont-appear – Vishal 2013-02-11 02:54:24