由于我需要地图的当前位置,因此我将代码用作:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager setDistanceFilter:10];
[locationManager startUpdatingLocation];
我在didFailWithError方法中得到错误:
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXX Inside didFailWithError in locationmanager method XXXXXXXXXXXXXXXXXXXXXXXXXX");
NSLog(@"Error: %@", error);
}
我在控制台中收到错误消息如下:
XXXXXXXXXXXXXXXXXXXXXXXXXX Inside didFailWithError in locationmanager method XXXXXXXXXXXXXXXXXXXXXXXXXX2010-12-06 17:58:12.335 ParkingAreaLocator[6992:207] Error: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
Wifi已开启。
我没有在模拟器和设备4.0 sdk中获取当前位置。
任何人都可以帮我解决这个问题。
谢谢你, Monish
答案 0 :(得分:0)
kCLErrorDomain = 0表示kCLErrorLocationUnknown
位置经理现在无法获得位置值。
如果位置服务无法立即检索位置修复,则会报告kCLErrorLocationUnknown错误并继续尝试。在这种情况下,您可以简单地忽略错误并等待新事件。
尝试精确度较低
答案 1 :(得分:0)
这比制作它简单得多。我从标题中假设你的视图中有一个MKMapView?如果是这样,您可以使用它来获取用户的位置。
在你的.h中,让这个视图控制器采用协议。
然后在.m中,执行此操作:
void viewDidLoad()
{
...
myMapView.showsUserLocation = YES;
...
}
(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)location
{
//Do whatever! that MKUserLocation is the location the map view just determined.
}