2013-11-04 43 views
0

我是Xcode的初学者。我想用别针来显示其他位置,而不是我当前的位置。我有经纬度值。现在我用地图查看它只显示当前位置。在MapKit中查找修正位置

-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    self.mapView.delegate=self; 
    [self.mapView setShowsUserLocation:YES]; 
    locationmanager=[[CLLocationManager alloc]init]; 
    [locationmanager setDelegate:self]; 

    [locationmanager setDistanceFilter:kCLDistanceFilterNone]; 
    [locationmanager setDesiredAccuracy:kCLLocationAccuracyBest]; 
} 

回答

0

使用MKMapViewClass。这里是我希望这会帮助你的代码。

- (void)viewDidLoad 
{ 
CLLocationCoordinate2D location; 
location.latitude = (double) 51.501468; 
location.longitude = (double) -0.141596; 

// Add the annotation to our map view 
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Buckingham Palace" andCoordinate:location]; 
[self.map addAnnotation:newAnnotation]; 
[newAnnotation release]; 
} 

- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views 
{ 
MKAnnotationView *annotationView = [views objectAtIndex:0]; 
id <MKAnnotation> mp = [annotationView annotation]; 
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500); 
[mv setRegion:region animated:YES]; 
[mv selectAnnotation:mp animated:YES]; 
}