0

デリゲートにメッセージ mapView:didUpdateUserLocation: が送信されない理由がわかりません。

viewDidLoad では、setShowUserLocation:YES で mapView に startUpdating を要求します。しかし、これを達成することは決してないようです。

助言がありますか?

#import "TrackViewController.h"
#import "MainWindowViewController.h"



@class MainWindowViewController;
@implementation TrackViewController

- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    NSLog(@"Init trackcontriller");
    self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if(self){

    locationManager = [[CLLocationManager alloc]init];

    [locationManager setDelegate:self];

    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];


    }
    return self;
}

-(IBAction) back:(id)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void) findLocation;
{
    NSLog(@"findlocation");
    [locationManager startUpdatingLocation];

}

-(void) foundLocation:(CLLocation *)loc
{
    NSLog(@"Foundlocation");
    CLLocationCoordinate2D coord = [loc coordinate];

    MKCoordinateRegion region =  MKCoordinateRegionMakeWithDistance(coord, 100, 100);
    [worldView setRegion:region animated:YES];


    [locationManager stopUpdatingLocation];
}

-(void)viewDidLoad
{
    NSLog(@"viewDidLoad");
    [worldView setShowsUserLocation:YES];
    [worldView setMapType:MKMapTypeHybrid];

}

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    NSLog(@"mapview didupdateUserlocation");
    CLLocationCoordinate2D loc = [userLocation coordinate];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 200, 200);
    [worldView setRegion:region animated:YES];
}

-(void)dealloc 
{

     [locationManager setDelegate:nil];
}

- (void) locationManager:(CLLocationManager *) manager
 didUpdateToLocation:(CLLocation *)newLocation
        fromLocation:(CLLocation *)oldLocation
// Deprecated i know
{
     NSLog(@"Locationanager didupdate tolocation from location");


NSTimeInterval t = [[newLocation timestamp] timeIntervalSinceNow];

if(t<-180){
    return;
}

    [self foundLocation:newLocation];
}

-(void)locationManager:(CLLocationManager *)manager
  didFailWithError:(NSError *)error
{
    NSLog(@"Could not find location: %@", error);
}

@end
4

1 に答える 1

0

CLLocationManagerとの位置情報サービスを混同していると思いますMapViewmapView:didUpdateUserLocation:のデリゲート メソッドですMKMapView。ユーザーの場所を更新するためにこのメソッドが必要なだけの場合は、 をインスタンス化する必要はありませんCLLocationManager。代わりに、あなたがしたように、単に言うだけですが、[worldView setShowsUserLocation:YES];
もちろん、実装するオブジェクトは、オブジェクトではなく、オブジェクトmapView:didUpdateUserLocation:のデリゲートでなければなりません! したがって、私の提案は、オブジェクトをオブジェクトのデリゲートとして設定することです。MKMapViewworldViewCLLocationManager
TrackViewControllerMKMapViewworldViewCLLocationManager

于 2013-07-28T18:58:54.650 に答える