首页 > 用ios自带的定位功能,怎么定位到香港去了?我在内地

用ios自带的定位功能,怎么定位到香港去了?我在内地

//定位方法
-(void)locate{
    if ([CLLocationManager locationServicesEnabled]) {
        self.myLocation = [[CLLocationManager alloc]init];
        self.myLocation.delegate = self;
        [self.myLocation setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
        if (SYSTEMVERSION >= 8.0) {
            [ self.myLocation requestAlwaysAuthorization];
        }
        //使用中授权
        if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized) {
            [self.myLocation startUpdatingLocation];
        }else{
            [Util showAlertView:@"您还没有授权本应用使用定位服务,请到 设置 > 隐私 > 位置 > 定位服务 中授权" ];
        }
    }else{
        [Util showAlertView:@"请开启定位:设置 > 隐私 > 位置 > 定位服务"];
    }
}
//定位成功回调方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
    [self.myLocation stopUpdatingLocation];
    _lastLocation= [locations lastObject];
    NSLog(@"latitude:%f",_lastLocation.coordinate.latitude);
    NSLog(@"longitude:%f",_lastLocation.coordinate.longitude);
    [_tableView.header beginRefreshing];
}

输出的结果:

latitude:22.284681
longitude:114.158177 

而且在设置的定位服务中看不到我的app,这是怎么回事?


模拟器? 真机?
模拟器不能定位呀~


楼主,我也遇到同样问题,怎么解决的啊??


你的Xcode开了定位,手机会变成设置的定位,重启就好


模拟器需要设置一下经纬度。 Simulator -> Debug -> Location -> CustomLocation 填写上

【热门文章】
【热门文章】