Iphone 使用span缩放到用户位置

Iphone 使用span缩放到用户位置,iphone,ios,zooming,cllocationmanager,html,Iphone,Ios,Zooming,Cllocationmanager,Html,这是我的密码。我收到了Location manager的回调,但它不想缩放到该位置 #import "MapViewController.h" @interface MapViewController () @property (nonatomic, strong) CLLocationManager *locationManager; @end @implementation MapViewController @synthesize mapView = _mapView; @s

这是我的密码。我收到了Location manager的回调,但它不想缩放到该位置

#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];


 }
如果需要,我可以发布头文件。我主要关心的是缩放。我只是不明白为什么它不起作用。

你的
-(void)locationManager:(CLLocationManager*)manager的代码没有更新到location:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation
似乎是对的

试着换线

[self.view insertSubview:mapView atIndex:0];
致:

可能是由于视图中的显示方式,
MKMapView
没有重新绘制自身。

您的
-(void)locationManager:(CLLocationManager*)管理器didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation
的代码似乎是正确的

试着换线

[self.view insertSubview:mapView atIndex:0];
致:


可能是因为
MKMapView
在视图中的显示方式,它没有重新绘制自身。

工作得很好。谢谢。现在我注意到另一个问题。改变那条线现在隐藏了我在地图上的一个uibutton。我需要在地图视图的顶部添加另一个子视图吗?对不起,我已经解决了。再次感谢您的回复。效果非常好。谢谢。现在我注意到另一个问题。改变那条线现在隐藏了我在地图上的一个uibutton。我需要在地图视图的顶部添加另一个子视图吗?对不起,我已经解决了。再次感谢您的回复。