0

好的,这是我尝试使用 CLLoactionManager

- (void)viewDidLoad {

    [super viewDidLoad];
    mapView=[[MKMapView alloc] initWithFrame:self.view.frame];
    //mapView.showsUserLocation=TRUE;
    mapView.delegate=self;
    [self.view insertSubview:mapView atIndex:0];


    CLLocationManager *locationManager=[[CLLocationManager alloc] init];
    locationManager.delegate=self;
    locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;

    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    mStoreLocationButton.hidden=FALSE;
    location=newLocation.coordinate;
    //One location is obtained.. just zoom to that location

    MKCoordinateRegion region;
    region.center=location;
    MKCoordinateSpan span;
    span.latitudeDelta=0.01;
    span.longitudeDelta=0.01;
    region.span=span;

    [mapView setRegion:region animated:TRUE];    
}

我的问题是这[locationManager startUpdatingLocation];似乎没有触发下一个方法。我错过了什么?我试过在第二种方法中设置断点,但它们永远不会捕获。显然它没有被使用。

4

2 回答 2

3

您应该考虑使用 CLLocationManager 来获取当前位置,以便为您的 MKMapView 提供正确的坐标。

CLLocationManager *locationManager = [[CLLocationManager alloc] init];
MKMapView *map = [[MKMapView alloc] init];

[locationManager startUpdatingLocation];

CLLocationCoordinate2D _coordinate = locationManager.location.coordinate;
MKCoordinateRegion extentsRegion = MKCoordinateRegionMakeWithDistance(_coordinate, 800, 800); 

[map setRegion:extentsRegion animated:YES];
于 2012-07-24T08:01:18.830 回答
0

看起来是一个不错的起点。为了放下大头针,您需要知道坐标。使用- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation将帮助您获取用户的位置,以便您可以创建一个MKAnnotationMKPinAnnotationViews. 一旦你开始,它就非常简单。

于 2012-07-24T04:35:00.490 回答