【问题标题】:Latitude Longitude IOS 4.3纬度经度IOS 4.3
【发布时间】:2012-01-07 15:54:40
【问题描述】:

我正在关注http://www.switchonthecode.com/tutorials/getting-your-location-in-an-iphone-application 教程,但我无法在我的 Xcode SDK 中获取 mi 纬度和经度。

- (void)viewDidLoad {
 [super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];

}


- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation
{

int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
                 degrees, minutes, seconds];
//latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
                   degrees, minutes, seconds];  
NSLog(@"%@ %@",longt, lat);

}

它不会在控制台中显示纬度和经度。 请帮帮我。

【问题讨论】:

  • 你在实现委托方法locationManager:didFailWithError:吗?如果是这样,是否有错误?如果没有,执行它,看看是否有错误。
  • 代码对我来说直接有效。在单一视图应用程序中。当应用要求使用您当前的位置时,您是否点击了确定?
  • 啊,我才意识到我使用的是iOS5。你得到:服务器不接受客户端注册 68. 在控制台中
  • 是的,当应用要求使用您的当前位置时,我点击确定
  • 你得到的是:服务器不接受控制台中的客户端注册 68

标签: objective-c ios xcode ios4


【解决方案1】:

您的代码看起来不错。如果它不起作用 - 问题不在这里。

确保:

  1. 您在设备(不是模拟器)上运行它
  2. 您的设备已安装 SIM 卡并已连接到蜂窝网络
  3. 最好将设备连接到具有互联网访问权限的 WiFi。

所有这些都将帮助 GPS 使用辅助 GPS 更快地定位。

另外,考虑到核心位置几乎立即返回最后一个已知位置。它已经过时并且可能是错误的,但会立即提供。如果根本没有得到任何东西 - 这看起来像是您设备上的核心位置问题,而不是应用程序。

另外,最好实现 locationManager:didFailWithError: 方法来捕获可能的错误。就像禁用的 GPS。

这是此方法的示例:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"GPS Error: %@", [error localizedDescription]);
}

3G 和早期 GPS 定位可能需要几分钟,4 和 4S 大约需要 10 秒(假设在这两种情况下都是晴朗的天空)

【讨论】:

  • 日志显示这些错误:错误:错误域=kCLErrorDomain Code=0“操作无法完成。(kCLErrorDomain错误0。)”有什么想法吗??
猜你喜欢
  • 2013-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多