【问题标题】:User location not showing用户位置不显示
【发布时间】:2016-03-29 22:27:51
【问题描述】:

我是 ios 编程新手。我在尝试显示带有当前用户位置的图钉时遇到问题。

@implementation ViewController 
@synthesize mapView;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.locationManager = [[CLLocationManager alloc]init];
    self.locationManager.delegate = self;
    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        [self.locationManager requestWhenInUseAuthorization];
    }
    CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];

    if (authorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
        authorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
        authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {

        [self.locationManager startUpdatingLocation];
        mapView.showsUserLocation = YES;
        [self.mapView delegate];

    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

info.plist 具有 NSLocationWhenIsUseUsageDescription 属性,但它不显示图钉也不放大用户位置。

【问题讨论】:

标签: ios objective-c mkmapview


【解决方案1】:

您可能想研究didUpdateUserLocation 方法。在您要求地图显示用户位置后,可能需要一些时间才能得到响应。当系统向您返回有关用户位置的数据时,将访问 didUpdateUserLocation 方法。 didUpdateUserLocation 是在您拥有用户位置后,您可以将代码用于对地图执行任何操作的地方。

【讨论】:

    【解决方案2】:

    试试这个代码,你要求它开始更新 if 块内的位置,这对我来说似乎不正确。

    我也不确定你想在 if 块中用这条线做什么。

    除此之外,您的方法中可能存在多个问题。我建议您查看一个很好的教程。

    [self.mapView 委托];

    self.locationManager = [[CLLocationManager alloc]init];
    self.locationManager.delegate = self;
        [self.locationManager startUpdatingLocation];
    
    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        [self.locationManager requestWhenInUseAuthorization];
    }
    
    CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];
    
    if (authorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
        authorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
        authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {
    
        mapView.showsUserLocation = YES;
        [self.mapView delegate];
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 1970-01-01
      相关资源
      最近更新 更多