0

现在,我正在尝试在完成其余作业之前测试在地图上注释图钉的概念。分配说明说不需要 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。

4

1 回答 1

0

首先确保该updateLocations方法实际被调用。该方法现在已被弃用,取而代之的是:

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

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

于 2013-02-11T02:42:18.553 回答