0

カスタム サークル オーバーレイをサブビューとして現在のユーザーの位置にリアルタイムで追従させるにはどうすればよいですか? 円のオーバーレイを表示して、ユーザーの位置の中心に到達することができましたが、ユーザーが移動 (GPS) すると、オーバーレイは静止したままになり、ユーザーを追跡しません。どうすれば修正できますか?前もって感謝します..

- (void)viewDidLoad {
[super viewDidLoad];



[self.mapView setRegion:MKCoordinateRegionMake(self.location.coordinate, MKCoordinateSpanMake(0.02, 0.02))];
[self configureOverlay];

[[self locationManager] startUpdatingLocation];

}

configureOverlay で:

        CircleOverlay *overlay = [[CircleOverlay alloc] initWithCoordinate:self.location.coordinate radius:self.radius];

    [self.mapView addOverlay:overlay];

    GeoQueryAnnotation *annotation = [[GeoQueryAnnotation alloc] initWithCoordinate:self.location.coordinate radius:self.radius];

    [self.mapView addAnnotation:annotation];

私も使ってみました:

 CLLocation *location = _locationManager.location;

    CLLocationCoordinate2D coordinate = [location coordinate];

座標を self.location.coordinate に置き換えます

アドバイスをいただければ幸いです。ありがとうございます

4

1 に答える 1

1

CLLocationManagerDelegate を実装することをクラスに伝えます

@interface YourClass () <CLLocationManagerDelegate>

次に、次のメソッドを追加します。

    #pragma mark CLLocationManagerDelegate Methods
    - (void)locationManager:(CLLocationManager *)manager
        didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
//You can change the overlay coordinates here. Even with an animation if you want.

    }

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSString *errorType = (error.code == kCLErrorDenied) ? @"Access Denied" : @"Unknown Error";
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error getting Location"message:errorType delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
    [alert show];
}

locationManager:didUpdateToLocation... メソッドは、ロケーション マネージャーがユーザーの位置の変化を検出するたびにトリガーされます。

乾杯。

編集 非常に重要なことを忘れていました。viewDidLoad メソッドで、クラスをデリゲートとして追加します。

self.locationmanager.delegate = self;
于 2012-09-28T12:26:36.720 に答える