1
這是我的代碼現在。我從位置管理器獲取回調,但它不想縮放到位置。使用跨度縮放到用戶位置
#import "MapViewController.h"
@interface MapViewController()
@property (nonatomic, strong) CLLocationManager *locationManager;
@end
@implementation MapViewController
@synthesize mapView = _mapView;
@synthesize mPlacemark = _mPlacemark;
@synthesize location = _location;
@synthesize mStoreLocationButton = _mStoreLocationButton;
@synthesize locationManager = _locationManager;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
mapView=[[MKMapView alloc] initWithFrame:self.view.frame];
//mapView.showsUserLocation=TRUE;
mapView.delegate=self;
[self.view insertSubview:mapView atIndex:0];
NSLog(@"locationServicesEnabled: %@", [CLLocationManager locationServicesEnabled] ? @"YES":@"NO");
if ([self locationManager] == nil) {
CLLocationManager *newLocationManager = [[CLLocationManager alloc] init];
[newLocationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[newLocationManager setDistanceFilter:kCLDistanceFilterNone];
[self setLocationManager:newLocationManager];
}
[[self locationManager] setDelegate:self];
[[self locationManager] startUpdatingLocation];
NSLog(@"Started updating Location");
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"Did update to location");
mStoreLocationButton.hidden=FALSE;
location=newLocation.coordinate;
MKCoordinateRegion region;
region.center=location;
MKCoordinateSpan span;
span.latitudeDelta=0.01;
span.longitudeDelta=0.01;
region.span=span;
[mapView setRegion:region animated:TRUE];
}
我可以張貼的頭文件如果需要的話。主要是我只關心縮放。我只是不明白爲什麼它不起作用。
完美工作。謝謝。 – Coltrane 2012-07-30 23:23:42
現在我注意到了另一個問題。現在改變這條線隱藏了我在地圖上的一個uibutton。我需要在mapview的頂部添加另一個子視圖嗎? – Coltrane 2012-07-30 23:31:51
對不起,弄明白了。再次感謝您的回覆。 – Coltrane 2012-07-30 23:52:36