0

我是 Xcode 的初学者。我想用别针显示另一个位置,而不是我当前的位置。我有纬度和经度值。现在我使用地图视图,它只显示当前位置。

-(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];
}
4

1 回答 1

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];
}
于 2013-11-04T06:44:55.497 回答