2013-07-05 3 views
0

enter image description hereMapview에서 한 번에 소스와 대상을 표시하는 방법은 무엇입니까?

경로를 표시하기 위해 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

http://stackoverflow.com/questions/5040175/iphone-mkmapview-set-map-region-to-show-all-pins-on-map – Ankur

+0

, min과 max는 _same_ 주석을 사용하여 설정됩니다. 또한 regionThatFits _는 MKCoordinateRegion을 반환합니다 (실제로지도의 영역을 변경하지 않음). 따라서 코드의 행이 실제로 아무것도 수행하지 않습니다. 대신 setRegion을 호출해야합니다. 폴리선을 그리는 것처럼 보이기 때문에,지도의 visibleMapRect를 MKPolyline의 boundingMapRect로 설정할 수 있습니다. – Anna

답변

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; 

} 도시 코드에

관련 문제