Ich verwende MKMapView in meinem großen Projekt. Wenn ich viel Annotation (über 700) lade und eine Linie zwischen diesen Punkten auf MapKit zeichne, bekomme ich die xcode-Fehlermeldung "Beendet wegen Speicherfehler" und App stürzt ab. können Sie auf Bild sehen:Wie ich lösen kann Beendet wegen Speicherfehler
.
Ich füge Zeile wie folgt aus:
wenn ich weniger als 700 Anmerkung haben, es funktioniert sehr gut. Ich denke, es hat ein Speicherproblem. Wie kann ich dieses Problem lösen?
// adding annodation
for (int i=0; i<[fetcher.locations count]; i++)//fetcher.locations is NSMutableArray and inside have locationInfoClass objects . locationInfoClass is hold CLLocationCoordinate2D.
{
locationInfoClass * loc=[fetcher2.locations objectAtIndex:i];
CLLocationCoordinate2D coordinate1;
coordinate1.latitude = loc.lat;
coordinate1.longitude = loc.lon;
myAnnotation * ann = [[myAnnotation alloc] initWithCoordinate:annCoordinate title:@"uniqtitle" subtitle:@"uniqsubtitle"];
[mapView addAnnotation:ann];
}
#pragma mark -
#pragma mark -mapview overlay
CLLocationCoordinate2D *coordinates
= malloc(sizeof(CLLocationCoordinate2D) * [mapView.annotations count]);
for (int i=0; i<[mapView.annotations count]; i++) {
myAnnotation * ann=[mapView.annotations objectAtIndex:i];
coordinates[i]=ann.coordinate;
}
self.routeLine = [MKPolyline polylineWithCoordinates:coordinates count:mapView.annotations.count]; // pinlerin sayısı ne kadarsa o kadar çizgi çiziyor.
free(coordinates);
[self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible
dispatch_async(dispatch_get_main_queue(), ^{
[self.mapView addOverlay:self.routeLine];
});
.h-Datei haben
@property (nonatomic, retain) MKPolyline *routeLine; //your line
@property (nonatomic, retain) MKPolylineView *routeLineView; //overlay view
MKMapView Delegatmethoden.
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
if(overlay == self.routeLine)
{
if(nil == self.routeLineView)
{
self.routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine];
self.routeLineView.fillColor = [UIColor redColor];
self.routeLineView.strokeColor = [UIColor redColor];
self.routeLineView.lineWidth = 3;
}
return self.routeLineView;
}
return nil;
}
/*
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500);
[mv setRegion:region animated:YES];
}*/
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"ftffggf";
pinView = (MKAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil)
pinView = [[MKAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID];
//pinView.pinColor = MKPinAnnotationColorGreen;
pinView.canShowCallout = YES;
//pinView.animatesDrop = YES;
UIImage * image=[UIImage imageNamed:@"pin.png"];
CGSize size=CGSizeMake(50, 63);//set the width and height
pinView.image = image
}
else {
[self.mapView.userLocation setTitle:@"I am here"];
}
pinView.centerOffset = CGPointMake(0,-23);
return pinView;
}
das ist die gesamte Nachricht? keine Rückverfolgung oder Ausnahmen? – nielsbot
ja Nachricht ist nur das. App wartet 30 Sekunden auf Annotation hinzufügen und Overlay hinzufügen. plötzlich zeigt sich diese Nachricht. –
Führen Sie Ihre App unter Instrumente aus und beobachten Sie das Speicherwachstum. Wenn dies die gleiche App wie Ihre andere Frage ist, bei der Sie mehr als 90 Threads haben, könnte das leicht das Problem sein. – bbum