用户位置未在地图中显示

时间:2013-03-12 06:08:02

标签: ios5 mkmapview mapkit cllocationmanager

我需要用蓝点圆圈在地图中显示用户当前位置。我使用了CLLocationManager。但mapview只显示。我发了自定义lat,很长。但是这个lat,很久都无法在地图中显示。

代码:

- (void)viewDidLoad
{
    UIView *vc=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

    [self.view addSubview:vc];
    MKMapView *map = [[MKMapView alloc] init]; 
    map.frame = CGRectMake(0, 0, 320, 480);

    map.showsUserLocation=YES;
  [self.view addSubview:map];
locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    [locationManager startUpdatingLocation];



    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
   // NSLog(@"OldLocation %f %f", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
   // NSLog(@"NewLocation %f %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);

    CLLocationCoordinate2D loc = [newLocation coordinate];

    NSLog(@"current longitude = %f  ,   current latitude = %f",loc.longitude,loc.latitude);
}

1 个答案:

答案 0 :(得分:1)

使用InterfaceBuilder,将地图视图拖放到屏幕上,勾选显示用户位置旁边的框。

此外,您不需要位置管理器来显示用户位置,mapview将负责处理。

相关问题