新的目标c!
我试图让我的地图视图缩放。我从书中的作业中复制了一些代码,但不知何故无法缩放。只显示未缩放的地图视图。
有什么建议么?请参阅下面的 viewController 代码。
另外-关于导入头文件和@class指令的区别的几句话会很棒!?
提前致谢
#import "TrackViewController.h"
#import "MainWindowViewController.h"
#import <MapKit/MapKit.h>
@class MainWindowViewController;
@implementation TrackViewController
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
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;
{
[locationManager startUpdatingLocation];
}
-(void) foundLocation:(CLLocation *)loc
{
CLLocationCoordinate2D coord = [loc coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 100, 100);
[worldView setRegion:region];
[locationManager stopUpdatingLocation];
}
-(void)viewDidLoad
{
[worldView setShowsUserLocation:YES];
[worldView setMapType:MKMapTypeHybrid];
}
-(void)dealloc
{
[locationManager setDelegate:nil];
}
- (void) locationManager:(CLLocationManager *) manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
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