【问题标题】:User location not showing in map地图中未显示用户位置
【发布时间】:2013-03-12 06:08:01
【问题描述】:

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

代码:

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

【问题讨论】:

    标签: ios5 mkmapview mapkit cllocationmanager


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多