0

我需要用蓝点圆圈在地图中显示用户当前位置。我使用了 CLLocationManager。但地图视图只显示。我发送了自定义纬度,经度。但是这个纬度,经度不能显示在地图上。

代码:

- (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);
}
4

1 回答 1

1

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

此外,您不需要位置管理器来显示用户位置,地图视图会处理这些。

于 2013-03-12T22:22:56.217 回答