簡體   English   中英

MKPolyline未在地圖視圖中顯示

[英]MKPolyline not being displayed in map view

我正在使用一個簡單的iOS應用程序,該應用程序從服務器檢索GeoJSON並將其顯示在地圖視圖上。 除了最后一部分,其他所有東西都在工作。 我檢索了GeoJSON,將其解析以創建MKPolyline,將該行提供給我的視圖(這是地圖的委托),然后將其添加到我的mapView中,但未顯示。 我對可能出問題的地方一無所知。

我有一個從服務器檢索數據的networking類,而我的視圖控制器是它的委托。 它收到這樣的行:

-(void) receiveRoutePolyline:(MKPolyline *)routeLine {
    NSLog(@"Received line");
    NSLog(@"%@", self.mapView.delegate);
    NSLog(@"%@", self);
    self.routeLine = routeLine;
    if (self.routeLine == nil) {
        NSLog(@"Nil duh!");
    }
    NSLog(@"%lu", (unsigned long)[self.routeLine pointCount]);
    [self.mapView addOverlay:self.routeLine level:MKOverlayLevelAboveLabels];
    NSLog(@"Set line on map");
}

如您所見,我一直在打印信息以查找任何錯誤。 這是函數的輸出:

2016-04-28 12:09:40.472 SinTraficoRouteAPIDemo[43189:1400965] Received line
2016-04-28 12:09:40.473 SinTraficoRouteAPIDemo[43189:1400965] <MapViewController: 0x78f37a90>
2016-04-28 12:09:40.474 SinTraficoRouteAPIDemo[43189:1400965] <MapViewController: 0x78f37a90>
2016-04-28 12:09:40.475 SinTraficoRouteAPIDemo[43189:1400965] 121
2016-04-28 12:09:40.475 SinTraficoRouteAPIDemo[43189:1400965] Set line on map

將視圖控制器正確設置為mapView的委托,但是,呈現方法為:

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
    NSLog(@"hi");
    if ([overlay isKindOfClass:[MKPolyline class]]) {
        MKPolyline *route = overlay;
        MKPolylineRenderer *routeRenderer = [[MKPolylineRenderer alloc] initWithPolyline:route];
        routeRenderer.strokeColor = [UIColor blueColor];
        routeRenderer.lineWidth = 10;
        return routeRenderer;
    }
    else {
        return nil;
    }
}

永遠不要在控制台上輸入“ hi”! 我什至嘗試添加過時的方法

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay {
    MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
    polylineView.strokeColor = [UIColor redColor];
    polylineView.lineWidth = 10;
    return polylineView;
}

看看是否可行,但沒有運氣。 任何幫助表示贊賞,謝謝。

編輯:查看控制器聲明

@interface MapViewController : UIViewController <MKMapViewDelegate, OptionsDelegate, RouteNetworkDelegate>

這段代碼工作正常。 該線已正確繪制在地圖上,問題是解析坐標並創建線的代碼。 它將緯度和經度向后設置,因此該線位於世界其他地方,對於我的縮放級別而言是不可見的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM