我不明白为什么没有向代表发送消息 mapView:didUpdateUserLocation:
在 viewDidLoad 中,我要求 mapView 使用 setShowUserLocation:YES 开始更新。但它就像它永远不会做到这一点。
有什么建议么?
#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