Problem in getting current location of a map in iphone sdk
As I need the current location of a map I used the code as:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager setDistanceFilter:10];
[locationManager startUpdatingLocation];
And I am getting the error in the didFailWithError methos as:
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXX Inside didFailWithError in locationmanager method XXXXXXXXXXXXXXXXXXXXXXXXXX");
NSLog(@"Error: %@", error);
}
And I am getting the error message in my console as follows:
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.)"
An开发者_如何学JAVAd the Wifi is on.
I am not getting the current location in both simulator and device 4.0 sdk.
Can any one please help me how to resolve this issue.
Thank you, Monish
kCLErrorDomain=0 means kCLErrorLocationUnknown
The location manager was unable to obtain a location value right now.
If the location service is unable to retrieve a location fix right away, it reports a kCLErrorLocationUnknown error and keeps trying. In such a situation, you can simply ignore the error and wait for a new event.
Try with less accuracy
This is a lot simpler than you're making it. I assume from the title that you've got an MKMapView in your view? If so, you can use it to get the user's location.
In your .h, have this view controller adopt the protocol.
Then in the .m, do this:
void viewDidLoad()
{
...
myMapView.showsUserLocation = YES;
...
}
(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)location
{
//Do whatever! that MKUserLocation is the location the map view just determined.
}
精彩评论