2016-06-14 12 views
0

Je suis exécuté dans mon application pour trouver un emplacement actuel, mais la première fois retourne lat lat long avec une localité dépendante, mais quand ils ont fait DidUpdateLocations ce temps passe à didFailWithError et return Domain = kCLErrorDomain Code = 0 "(null)". J'ai essayer solution diffrent diffrent commeDomain = kCLErrorDomain Code = 0 "(null)" dans n'importe quel périphérique ios

  1. Content Reset et paramètres
  2. Dans Xcode, Produit -> Système -> Modifier Scheme, puis annuler le "Autoriser Emplacement Simulator" et l'iOS Simulator et réinitialiser le contenu et Réglage et à nouveau sur le Xcode, répétez la première étape. Pour le simulateur iOS et réinitialiser.

mais aucun de ces travaux

mon code pour cela est ici:

- (void)locationManager:(CLLocationManager *)manager 
didUpdateLocations:(NSArray *)locations{ 

NSLog(@"didUpdateToLocation: %@", [locations lastObject]); 
CLLocation *currentLocation = [locations lastObject]; 


if (currentLocation != nil) 
{ 
    self.lblLongitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.longitude]; 
    self.lblLatitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.latitude]; 
} 


NSLog(@"Resolving the Address"); 


[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) { 
    NSLog(@"Found placemarks: %@, error: %@", placemarks, error); 
    if (error == nil && [placemarks count] > 0) { 
     placemark = [placemarks lastObject]; 
     NSString *geoMapItem = placemark.description; 
     NSRange start = [geoMapItem rangeOfString:@"dependentLocality"]; 

     NSRange end = [geoMapItem rangeOfString:@")" options:NSCaseInsensitiveSearch range:NSMakeRange(start.location, 1000)]; 
     NSString *dataString = [geoMapItem substringWithRange:NSMakeRange(start.location, end.location - start.location + end.length)]; 
     dataString = [dataString stringByReplacingOccurrencesOfString:@"\n" withString:@""]; 
     dataString = [dataString stringByReplacingOccurrencesOfString:@" " withString:@""]; 
     dataString = [dataString stringByReplacingOccurrencesOfString:@"\"" withString:@""]; 

     start = [dataString rangeOfString:@"("]; 
     end = [dataString rangeOfString:@")"]; 
     NSLog(@"datastring===>%@",dataString); 
     lblAddress.text = [NSString stringWithFormat:@"%@ \n%@ %@\n%@\n%@", 
         dataString, 
         placemark.postalCode, placemark.locality, 
         placemark.administrativeArea, 
         placemark.country]; 
    } else 
    { 
     NSLog(@"%@", error.debugDescription); 
    } 
} ];} 

après la mise à jour l'emplacement première fois va à l'erreur bloc

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ 
NSLog(@"didFailWithError%@",error); 
UIAlertView *errorAlert = [[UIAlertView alloc] 
          initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
[errorAlert show];} 

et obtenir cette erreur didFailWithErrorError Domain = kCLErrorDomain Code = 0 "(null)"

+0

L'exécutez-vous sur un simulateur? –

+0

Avez-vous consulté cette réponse? http://stackoverflow.com/questions/1409141/location-manager-error-kclerrordomain-error-0 – Dominic

+0

non j'essaie sur ipad, iphone5s, iphone6. –

Répondre

0

bonjour les gars j'ai trouvé les solutions de ma propre question. Une erreur mineure faite par moi. Je vérifie currentLocation! = Nil à chaque fois, c'est la mise à jour mais l'emplacement actuel Lat Long n'est pas défini.

//if (currentLocation != nil) 
//{ 
    self.lblLongitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.longitude]; 
    self.lblLatitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.latitude]; 
//} 

maintenant c'est OK!