美文网首页
UIWebView开始定位权限

UIWebView开始定位权限

作者: iOS乐乐 | 来源:发表于2017-07-28 16:51 被阅读0次
#import <CoreLocation/CoreLocation.h>
<CLLocationManagerDelegate>

    self.locationManager=[[CLLocationManager alloc]init] ;
    
    self.locationManager.delegate=self;
    
    [self.locationManager startUpdatingLocation];
    
    self.locationManager.distanceFilter=kCLLocationAccuracyBest;
    
    [self.locationManager requestWhenInUseAuthorization];

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    // 获取经纬度
    NSLog(@"纬度:%f",newLocation.coordinate.latitude);
    NSLog(@"经度:%f",newLocation.coordinate.longitude);
    
    UIAlertView*alert=[[UIAlertView alloc]initWithTitle:[NSString stringWithFormat:@"%f",newLocation.coordinate.latitude] message:[NSString stringWithFormat:@"%f",newLocation.coordinate.longitude] delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
    
    [alert show];
    
    // 停止位置更新
//    [manager stopUpdatingLocation];
}

// 定位失误时触发
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"error:%@",error);
}

plist全新
Privacy - Location Usage Description     访问位置
Privacy - Location When In Use Usage Description  使用您的位置获取当前的位置信息,通过设置页面的隐藏位置功能可随时手动隐藏位置信息。
Privacy - Location Always Usage Description  使用您的位置获取当前的位置信息,通过设置页面的隐藏位置功能可随时手动隐藏位置信息。

相关文章

网友评论

      本文标题:UIWebView开始定位权限

      本文链接:https://www.haomeiwen.com/subject/jerflxtx.html