【已解决】【奇葩5】iOS 定位到香港
来源:互联网 发布:京东众包 软件打不开 编辑:程序博客网 时间:2024/06/08 13:52
现象:
使用 iPhone 或者 iPad 经常定位到香港(22.284681,114.158177)去。重启设备后又可以了。但是隔一会儿,又到香港去了。
//// GPSViewController.m// Fly Survey//// Created by dinghongyan on 13-7-5.////#import "GPSViewController.h"#import "ZYFileUtil.h"#import "ZYDateUtil.h"#import <CoreLocation/CoreLocation.h>#import "ZYMyLog.h"@interface GPSViewController ()<CLLocationManagerDelegate>@end@implementation GPSViewController-(id)init{ if (self = [super init]) { if ([CLLocationManager locationServicesEnabled]) { self.lm = [[CLLocationManager alloc] init]; self.lm.delegate = self; self.lm.desiredAccuracy = kCLLocationAccuracyBest; } } return self;}-(void)startGPS{ if (self.lm) { [self.lm startUpdatingLocation]; }}-(void)stopGPS{ if (self.lm) { [self.lm stopUpdatingLocation]; }}//iOS 8- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{ switch (status) { case kCLAuthorizationStatusNotDetermined: //用户还没有选择是否授权 if ([self.lm respondsToSelector:@selector(requestAlwaysAuthorization)]) { [self.lm requestAlwaysAuthorization]; } break; case kCLAuthorizationStatusAuthorizedAlways: case kCLAuthorizationStatusAuthorizedWhenInUse: //有定位权限,开始定位,并计时 [self.delegate gpsStartLocating]; break; default: //没有定位权限,提示 [self.delegate gpsLocatedFailed]; break; } }//iOS6.0以上推荐使用方法-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ //此处locations存储了持续更新的位置坐标值,取最后一个值为最新位置,如果不想让其持续更新位置,则在此方法中获取到一个值之后让locationManager stopUpdatingLocation CLLocation *currentLocation = [locations lastObject]; [self saveLocation:currentLocation]; [self.lm stopUpdatingLocation];}//iOS6.0以下- (void) locationManager: (CLLocationManager *) manager didUpdateToLocation: (CLLocation *) newLocation fromLocation: (CLLocation *) oldLocation{ [self saveLocation:newLocation]; [self.lm stopUpdatingLocation]; }- (void)saveLocation:(CLLocation *)newLocation{ //纬度 NSString *latitude = [[NSString alloc] initWithFormat:@"%f",newLocation.coordinate.latitude]; //经度 NSString *longitude = [[NSString alloc] initWithFormat:@"%f",newLocation.coordinate.longitude]; //2015-1-30 过滤定位香港的 if ([latitude isEqualToString:@"22.284681"] && [longitude isEqualToString:@"114.158177"]) { //定位不正确,请重启定位服务 [self.delegate gpsInHongKong]; //保存定位信息 NSString *timeNow = [ZYDateUtil timeNow:@"yyyy-MM-dd HH:mm:ss"]; [[ZYMyLog sharedMyLog] appendString:[NSString stringWithFormat:@"更新位置:(%@,%@), 定位在香港,不允许通过",latitude,longitude]]; self.longitude = @""; self.latitude = @""; self.time = timeNow; }else{ //保存定位信息 NSString *timeNow = [ZYDateUtil timeNow:@"yyyy-MM-dd HH:mm:ss"]; [[ZYMyLog sharedMyLog] appendString:[NSString stringWithFormat:@"更新位置:(%@,%@)",latitude,longitude]]; self.longitude = longitude; self.latitude = latitude; self.time = timeNow; } }- (void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSString *timeNow = [ZYDateUtil timeNow:@"yyyy-MM-dd HH:mm:ss"]; [[ZYMyLog sharedMyLog] appendString:[NSString stringWithFormat:@"定位出错:%@",error]]; self.time = timeNow; self.longitude = @""; self.latitude = @""; [self.lm stopUpdatingLocation]; [self.delegate gpsLocatedFailed];}@end
一开始认为这个是 iOS 本身的bug,因为定位就是调一个接口而已,我能干涉的并不多。而且,出现定位香港之后,我使用高德地图、苹果地图,都是定位到香港。因此我百分之百认定,就是系统bug。
直到跟老公一直争论,老公坚持认为是我的app的问题,于是用他的 iPhone(未安装我的app)搞来搞去,就是没有出现定位香港。
后来在网上搜索,也没有人遇到跟我一样的情况,我开始怀疑了。
再用测试机测试,当我的app中出现定位香港之后,使用高德地图定位,依然是香港。 这时候,我把我的app退出,再用高德地图去定位的时候,神奇的事情发生了,定位对了!果然,出问题的是我的app,不是系统bug。
在网上搜索了定位的这个坐标(22.284681,114.158177), 是一个苹果店。 于是猜想,会不会是定位没成功的时候,先返回这个值,然后继续定位的呢?
但是去掉时间限制之后,还是一直定位香港,目前无解。
======== 2015-2-3 更新 ============
解决办法:
偶然看到一篇文章:xcode4.2 模拟器定位
原来xcode里面可以模拟一个位置,检查了下自己模拟器中的设置:
果然是在香港的。难怪只要退出我的app,就定位正确了。
于是改成Don't Simulate Location,再运行我的app,果然没有问题了。
再改成别的位置,确实定位到对应的地方了。
至此,奇葩终于解开!
0 0
- 【已解决】【奇葩5】iOS 定位到香港
- 【已解决】奇葩4: iOS定位,iPhone可以很快定位,但是iPad一直定位不了
- MVC Session两次赋值问题,无法传递等奇葩【已解决】
- htm5 页面跳转在android出现的奇葩问题 【已解决】
- 百度定位mLocClient.isStarted();返回false[已解决]
- iOS奇葩问题总结
- iOS UITextField系统警告问题~已解决
- 【已解决】iPhone/iOS中保存自定义对象(Custom Object/Custom Class)的数组(NSMutableArray/NSArray)到NSUserDefaults
- IOS 定位服务 定位到城市具体路段
- 定位到行的快捷键iOS
- 一个奇葩bug的解决
- 深圳到香港
- 香港到武汉
- iOS开发中的奇葩技巧
- iOS 证书的奇葩问题
- iOS 奇葩问题,记录大全
- 解决百度地图定位初始化 先初始化到北京,后定位到所在地的问题
- 解决ASP.NET Web Applicatio超时时间已到
- 最长上升子序列 POJ2533
- 【Android应用开发】Intent和PendingIntent的区别
- RadioStream应用源码完整版(iphone版和ipad版)
- 使用ajaxFileUpload实现文件异步上传
- jsp页面引入的标签库
- 【已解决】【奇葩5】iOS 定位到香港
- 【水题】 Codeforces Round #289 509A Maximum in Table
- MVC之-- ViewData vs ViewBag vs TempData vs Session
- live555源代码分析与代码下载链接
- 最快最简单的排序——桶排序
- 更简约的用户账号设计:只需要本人实际姓名、E-mail和手机号码任选其一,无需密码
- 前一段时间没事用c#写了一个串口程序,这里总结一下自己的经验
- 使用 DrMemory 发现内存编程错误
- mysql安装