iPhone GPS问题模拟器没有反应

时间:2010-10-21 12:11:14

标签: iphone objective-c gps

我正在尝试创建简单的GPS应用程序,只是为了在模拟器中显示简单的数据。我没有错误只是无法获取数据。 “didFailWithError”方法是我唯一可以上班的方法:),这就是代码:

- (void)viewDidLoad 
{  
 [super viewDidLoad];

 lm = [[CLLocationManager alloc] init];
 if([CLLocationManager locationServicesEnabled])
 {
  lm.delegate = self;
  lm.desiredAccuracy = kCLLocationAccuracyBest;
  //lm.distanceFilter = 1000.0f;
  [lm startUpdatingLocation];
 }

}


- (void) locationManager: (CLLocationManager *) manager
didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation{
 NSString *lat = [[ NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];
 txtLatitude.text = lat;

 NSString *lng = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];
 txtLongitude.text = lng;

 NSString *acc = [[NSString alloc] initWithFormat:@"%g", newLocation.horizontalAccuracy];
 txtAccuracy.text = acc;

 [acc release];
 [lat release];
 [lng release];
}
- (void) locationManager:(CLLocationManager *)manager 
didFailWithError: (NSError *) error
{
 NSString *msg = [[NSString alloc] initWithString:@"Error obtaining location"];
 UIAlertView *alert = [[ UIAlertView alloc] initWithTitle:@"Error" 
              message:msg 
             delegate:nil 
             cancelButtonTitle:@"Done" 
             otherButtonTitles:nil];
 [alert show];
 [msg release];
 [alert release];
}

1 个答案:

答案 0 :(得分:2)

它在模拟器中永远不会移动。

http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/125-Using_iPhone_Simulator/iphone_simulator_application.html

“核心位置功能

CoreLocation框架在模拟器中报告的重定位固定在以下坐标(精度100米),对应于1 Infinite Loop,Cupertino,CA 95014。

纬度:37.3317北 经度:122.0307西“

您可以尝试添加一个简单的随机或定时事件,该事件将didUpdate ...方法明确地与您偏好的假数据相关联。