用到ios自带的定位,想把当前位置在地图上标记出来,定位位置很准确,但是定位的位置却没有在mapview控件的中央,有哪位碰到过这样得问题吗?
以下是代码
@implementation MyMap001ViewController { MKMapView *mapview; CLLocationManager *locationManager; } -(void)viewDidLoad { mapview=[[MKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)]; mapview.showsUserLocation = YES; mapview.mapType = MKMapTypeSatellite; [self.view addSubview:mapview]; locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; [locationManager startUpdatingLocation]; } - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { [locationManager stopUpdatingLocation]; NSString *strLat = [NSString stringWithFormat:@"%.4f",newLocation.coordinate.latitude]; NSString *strLng = [NSString stringWithFormat:@"%.4f",newLocation.coordinate.longitude]; NSLog(@"Lat: %@ Lng: %@", strLat, strLng); CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(newLocation.coordinate.latitude,newLocation.coordinate.longitude); float zoomLevel = 0.002; MKCoordinateRegion region = MKCoordinateRegionMake(coords,MKCoordinateSpanMake(zoomLevel, zoomLevel)); [mapview setRegion:[mapview regionThatFits:region] animated:YES]; }
本来就不在中点的。
给你个category,你加到工程中,在mapview需要显示CLLocationCoordinate2D的地方调用就行了。
MapViewUtil.h
MapViewUtil.m