用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,这是怎么回事?

阅读 8.1k
4 个回答

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

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

新手上路,请多包涵

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

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题