MKPolyLine 在 MAP 上不可见

发布于 2024-12-17 16:49:55 字数 2346 浏览 0 评论 0原文

我有以下代码...

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]; 

但折线在地图上不可见。折线正在使用我检查过的值进行初始化。

i have the following code...

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]; 

but the polyline is not visible on map. The polyline is getting initialized with values that I have checked..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蘑菇王子 2024-12-24 16:49:55

我这边的菜鸟错误...忘记实现 MKMapViewDelegate 方法..

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id < MKOverlay >)overlay{

}

Noob mistake on my side... Forgot to implement the MKMapViewDelegate method..

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id < MKOverlay >)overlay{

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文