2011-11-21 47 views
0

我有以下代碼...MKPolyLine不可見的MAP

DistanceInformation *distanceInformation=[[DistanceInformation alloc]init]; 

    NSArray *latLongArray=[distanceInformation calculateDistance]; 
    [distanceInformation release]; 
    NSLog(@"lat l %@",latLongArray); 
    NSUInteger length,count; 
    length = [[latLongArray objectAtIndex:0] count]; 


    //Calcualte center of the map based on current location and airport location 
    CLLocationCoordinate2D centerOfMap; 

    centerOfMap.latitude = (27.1766700 + 28.6361600)/2; 
    centerOfMap.longitude = (78.0080700 + 78.0526500)/2; 

    //Set map span according to the distance between airport and user location 
    CGFloat zoomingLevel; 

    //set the zoom level of the map according to the distance to airport 
    if([[latLongArray objectAtIndex:2] intValue] <= 50) 
     zoomingLevel = 0.2; 
    else if(([[latLongArray objectAtIndex:2] intValue] > 50)&&([[latLongArray objectAtIndex:2] intValue] <= 100)) 
     zoomingLevel = 0.6; 
    else if(([[latLongArray objectAtIndex:2] intValue]> 100)&&([[latLongArray objectAtIndex:2] intValue] <= 500)) 
     zoomingLevel = 1.7; 
    else if(([[latLongArray objectAtIndex:2] intValue] > 500)&&([[latLongArray objectAtIndex:2] intValue] <= 1000)) 
     zoomingLevel = 2.0; 
    else 
     zoomingLevel = 2.5; 

    NSLog(@"Center of map: %f, %f",centerOfMap.latitude, centerOfMap.longitude); 
    MKCoordinateRegion region; 
    MKCoordinateSpan span; 
    span.latitudeDelta=zoomingLevel; 
    span.longitudeDelta=zoomingLevel; 

    region.span = span; 
    region.center = centerOfMap; 

    [mapView setRegion:region animated:TRUE]; 
    [mapView regionThatFits:region]; 

    CLLocationCoordinate2D coords[length]; 

    for (count = 0; count<length; count++) { 
     NSLog(@"coo "); 
     coords[count] = CLLocationCoordinate2DMake([[[latLongArray objectAtIndex:0] objectAtIndex:count] doubleValue], [[[latLongArray objectAtIndex:1] objectAtIndex:count] doubleValue]); 
    } 



    //Display polyline containing route points as an overlay over the mapview 
    MKPolyline *polyLine=[MKPolyline polylineWithCoordinates:coords count:length]; 
    NSLog(@"polyLine.pointCount %d",polyLine.pointCount) ; 
    [mapView addOverlay:polyLine]; 
    [polyLine release]; 

但折線不是在地圖上是可見的。折線是越來越與我檢查值初始化..

+1

你也實現了MKMapViewDelegate方法: - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id < MKOverlay >)是否覆蓋? – Luke

+0

它現在工作嗎? :) – Luke

回答

1

在我身邊菜鳥錯誤...忘記實現MKMapViewDelegate方法..

​​