1
新的目標c!它爲什麼不放大?
我試圖讓我的mapview放大。我從書中的作業中複製了一些代碼,但它不會縮放。只顯示unzoomed mapview。
有什麼建議嗎?請參閱下面的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
我剛剛使用setRegion? 我應該在哪裏嘗試打印CLLocationCoordinate2d對象? – Anders
它是一種不同的方法。 setRegion與setRegion不同:動畫: –