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];、次のメソッドを起動しないように見えることです。私は何が欠けていますか?2 番目の方法でブレークポイントを設定しようとしましたが、キャッチされません。明らかに使われていません。

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 に答える