我在我的应用程序中使用 mkmapview 它包含多个折线叠加和多个自定义注释,在运行应用程序时经常收到内存警告,我很挣扎
提前致谢。
for (int i = 0; i<[latArray count]-1; i++)
{
NSString *lat1 = [latArray objectAtIndex:i];
NSString *longi1 = [longArray objectAtIndex:i];
firstPlace = CLLocationCoordinate2DMake([lat1 doubleValue], [longi1 doubleValue]);
NSString *lat2 = [latArray objectAtIndex:i+1];
NSString *longi2 = [longArray objectAtIndex:i+1];
secPlace = CLLocationCoordinate2DMake([lat2 doubleValue], [longi2 doubleValue]);
[self directionRequest:firstPlace :secPlace index:i];
}
-(void)directionRequest:(CLLocationCoordinate2D )firstCord :(CLLocationCoordinate2D )secCord index:(int)index
{
@try
{
MKPlacemark *source=[[MKPlacemark alloc]initWithCoordinate:firstCord addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil]];
MKMapItem *sourceMapItem=[[MKMapItem alloc]initWithPlacemark:source];
[sourceMapItem setName:@""];
MKPlacemark *destination=[[MKPlacemark alloc]initWithCoordinate:secCord addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil]];
MKMapItem *destinationMapitem=[[MKMapItem alloc]initWithPlacemark:destination];
[destinationMapitem setName:@""];
MKDirectionsRequest *dirRequest=[[MKDirectionsRequest alloc]init];
[dirRequest setSource:sourceMapItem];
[dirRequest setDestination:destinationMapitem];
// dirRequest.requestsAlternateRoutes = YES;
[dirRequest setTransportType:MKDirectionsTransportTypeAutomobile];
MKDirections *direction=[[MKDirections alloc]initWithRequest:dirRequest];
[direction calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error)
{
// NSLog(@"response = %@",response);
NSArray *arrRoutes = [response routes];
[arrRoutes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
MKRoute *rout = obj;
MKPolyline *line = [rout polyline];
[iMapView addOverlay:line];
}];
}];
}
@catch (NSException *exception)
{
}
}