无法使MKannotate pin显示在我的地图上

时间:2013-02-10 20:58:00

标签: iphone objective-c mkannotation

现在我正在尝试在完成剩下的任务之前测试在地图上注释图钉的概念。赋值指令表示不需要CLLocationManager。到目前为止,我已经尝试在我的MKannotate类的特定实例上调用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。

1 个答案:

答案 0 :(得分:0)

首先确保实际调用updateLocations方法。该方法现在已被弃用,以支持:

- (void) locationManager:(CLLocationManager *) manager didUpdateLocations:(NSArray *)locations { }

你应该从那里调用foundLocation方法。