0

在此处输入图像描述

我正在使用 MKMapView 来显示路线。我想缩小这张地图,以便一次显示目的地的两个来源。

如何根据距离缩小地图,以便在一个屏幕上显示整个路线。

我正在使用这段代码:

double maxLatitude = annotation.coordinate.latitude;
double maxLongitude = annotation.coordinate.longitude;
double minLatitude = annotation.coordinate.latitude;
double minLongitude =  annotation.coordinate.longitude;
MKCoordinateRegion region;
region.center.latitude = (minLatitude + maxLatitude) / 2;
region.center.longitude = (minLongitude + maxLongitude) / 2;

region.span.latitudeDelta = (maxLatitude - minLatitude) * MAP_PADDING;

region.span.latitudeDelta = (region.span.latitudeDelta < MINIMUM_VISIBLE_LATITUDE)
? MINIMUM_VISIBLE_LATITUDE
: region.span.latitudeDelta;

region.span.longitudeDelta = (maxLongitude - minLongitude) * MAP_PADDING;


[self.mapView addAnnotation:annotation];

[self.mapView regionThatFits:region];
4

1 回答 1

0

可以通过下面的方法试试

 for (int i = 1; i<[arrayOfPointsToFindDistance count]; i++) {
            connection_listdata *detail_connection=[arrayOfPointsToFindDistance objectAtIndex:i];
            [self findDistancewithConnecionList:detail_connection];

 }

findDistancewithConnecionList 方法如下。

-(void)findDistancewithConnecionList:(connection_listdata *)connectionlist{
NSLog(@"sssssss");

CLLocation *oldLoc = [[CLLocation alloc] initWithLatitude:connectionlist.coordinate_connection.latitude longitude: connectionlist.coordinate_connection.longitude];
for(int i =0; i<[mapArray count];i++){
    NSLog(@"ghsghshhs");
    NSMutableArray *firstArrayTemp = [mapArray objectAtIndex:i];
    connection_listdata *detail_connection=[firstArrayTemp objectAtIndex:0];
    CLLocation *newLoc = [[CLLocation alloc] initWithLatitude:detail_connection.coordinate_connection.latitude longitude: detail_connection.coordinate_connection.longitude];
    CLLocationDistance d = [newLoc distanceFromLocation:oldLoc];

    NSLog(@"distanceeeee:%f",d);


    if(d <= 500){
        NSLog(@"foundddd");
        NSLog(@"maparray values= %@",mapArray);
        [firstArrayTemp addObject:connectionlist];
        [mapArray addObject:firstArrayTemp];
        return;

    }
[newLoc release];
}

NSMutableArray *array = [[NSMutableArray alloc]init];
[array addObject:connectionlist];
[mapArray addObject:array];
[array release];
[oldLoc release];

return;

}

于 2013-07-05T11:29:25.437 回答