我不明白爲什麼委託不發送該郵件的MapView:didUpdateUserLocation:委託方法送交
在viewDidLoad中我問的MapView與setShowUserLocation到startUpdating: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
您是否將此類設置爲地圖視圖的代表? – rdelmar