如何在Mapview中一次显示源和目的地?

时间:2013-07-05 09:58:35

标签: iphone xcode maps mkmapview

enter image description here

我正在使用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];

1 个答案:

答案 0 :(得分: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;

}