Dummer CoreLocation Error...
-
-
Code ?
-
Gibts nicht viel:
Und ja, der Variablenname geoDataLat/LngFloat ist irreführend
lg -
Reb00t schrieb:
Gibts nicht viel:
Und ja, der Variablenname geoDataLat/LngFloat ist irreführend
lg
Da der Fehler *nach* dem NSLog kommt, reicht der Codeschnipsel nicht um etwas dazu zu sagen. Und ob er überhaupt damit zu tun hat.
-- hns -
Das sind die Codezeilen, die dafür ausschlaggebend sind, weil ich die zusätzlich hinzugefügt habe!
Ohne die Zeilen Code funktioniert es eh! Außerdem handelt es sich ja um eine CORELOCATION Error
und diese Zeilen befassen sich nunmal damit. Zudem kommt nach NSLog nichts spektakuläres mehr...
Aber der vollständigkeit halber nochmal die ganze Methode:
Alles anzeigenQuellcode
- - (void)viewWillAppear:(BOOL)animated
- {
- userLoc = self.stationMapView.userLocation.location;
- NSError *error = nil;
- self.stationMapView = [[[MKMapView alloc] initWithFrame:self.view.bounds] autorelease];
- geoData = [NSString stringWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?address=%@,+Oesterreich&sensor=true", [[VariableStore sharedInstance].stationName objectAtIndex:[[VariableStore sharedInstance].selectedCell intValue]]]] encoding:NSUTF8StringEncoding error:NULL];
- geoDataDictionary = [NSDictionary dictionaryWithJSONString:geoData error:&error];
- geoDataLat = [NSMutableString stringWithFormat:@"%@", [geoDataDictionary valueForKeyPath:[NSString stringWithFormat:@"results.geometry.location.lat", [[VariableStore sharedInstance].keyArray objectAtIndex:[[VariableStore sharedInstance].selectedCell intValue]]]]];
- geoDataLng = [NSMutableString stringWithFormat:@"%@", [geoDataDictionary valueForKeyPath:[NSString stringWithFormat:@"results.geometry.location.lng", [[VariableStore sharedInstance].keyArray objectAtIndex:[[VariableStore sharedInstance].selectedCell intValue]]]]];
- [geoDataLat deleteCharactersInRange:(NSRange){0,7}];
- NSRange matchLat = [geoDataLat rangeOfString:@"\""];
- NSInteger matchLocationLat = matchLat.location;
- NSInteger deleteFromLat = matchLocationLat - 1;
- NSInteger deleteToLat = [geoDataLat length] - deleteFromLat;
- [geoDataLat deleteCharactersInRange:(NSRange){deleteFromLat, deleteToLat}];
- [geoDataLng deleteCharactersInRange:(NSRange){0,7}];
- NSRange matchLng = [geoDataLng rangeOfString:@"\""];
- NSInteger matchLocationLng = matchLng.location;
- NSInteger deleteFromLng = matchLocationLng - 1;
- NSInteger deleteToLng = [geoDataLng length] - deleteFromLng;
- [geoDataLng deleteCharactersInRange:(NSRange){deleteFromLng, deleteToLng}];
- double geoDataLatFloat = [geoDataLat doubleValue];
- double geoDataLngFloat = [geoDataLng doubleValue];
- geoDataLat = nil;
- [geoDataLat release];
- geoDataLng = nil;
- [geoDataLng release];
- CLLocationCoordinate2D location;
- location.latitude = geoDataLatFloat;
- location.longitude = geoDataLngFloat;
- stationLoc = [[CLLocation alloc] initWithLatitude:location.latitude longitude:location.longitude];
- Annotation *anno = [[Annotation alloc] initWithUserLocation];
- [anno setCoordinate:location];
- [anno setTitle:[NSString stringWithFormat:@"%@", [[VariableStore sharedInstance].stationName objectAtIndex:[[VariableStore sharedInstance].selectedCell intValue]]]];
- [anno setSubtitle:[NSString stringWithFormat:@"%@%@", [[VariableStore sharedInstance].dataDictionary valueForKeyPath:[NSString stringWithFormat:@"%@.v", [[VariableStore sharedInstance].keyArray objectAtIndex:[[VariableStore sharedInstance].selectedCell intValue]]]], @" nSv/h"]];
- [self.stationMapView addAnnotation:anno];
- MKCoordinateSpan span;
- span.latitudeDelta = 0.10;
- span.longitudeDelta = 0.20;
- MKCoordinateRegion region;
- region.center = location;
- region.span = span;
- [self.stationMapView setRegion:region animated:YES];
- [self.stationMapView setCenterCoordinate:location animated:YES];
- self.stationMapView.userInteractionEnabled = false;
- [stationMapView selectAnnotation:[[stationMapView annotations]objectAtIndex:0] animated:YES];
- CLLocationDistance distance = [userLoc distanceFromLocation:stationLoc];
- NSLog(@"Distance: %f", distance);
- [self.view addSubview:self.stationMapView];
- }
lg, Reb00t
//EDIT:
By the way: Weiß jemand, wie man die Sections in einer TableView handelt?
Für jede Section, will ich die Daten aus einem NSMutableArray von x-y angezeigt haben.
Bsp.:
Section 1: 1-10
Section 2: 11-20
Section 3: 21-30
usw. -
Ich würde das eher mal in viewDidAppear:animated: aufrufen.
-
Reb00t schrieb:
Das sind die Codezeilen, die dafür ausschlaggebend sind, weil ich die zusätzlich hinzugefügt habe!
Ohne die Zeilen Code funktioniert es eh! Außerdem handelt es sich ja um eine CORELOCATION Error
und diese Zeilen befassen sich nunmal damit. Zudem kommt nach NSLog nichts spektakuläres mehr...
Aber der vollständigkeit halber nochmal die ganze Methode:
Du kannst in der Methode nicht davon ausgehen, dass die View-Hierarchie etabliert ist.
Den unspektakulären Aufruf solltest Du hier icht machen.I would be embarrassed if they did not spy on me. -
Jo dann nehme ich es raus und dann?
Die MapView wird ja programmatisch erzeugt... Also muss ich die wohl an meine View hängen?! -
Hast du mal das gemacht, was ich gesagt habe?
Reb00t schrieb:
Jo dann nehme ich es raus und dann?
Die MapView wird ja programmatisch erzeugt... Also muss ich die wohl an meine View hängen?!