简体   繁体   English

MKPolyline未在地图视图中显示

[英]MKPolyline not being displayed in map view

I am working on a simple iOS app that retrieves GeoJSON from a server and displays it on a map view. 我正在使用一个简单的iOS应用程序,该应用程序从服务器检索GeoJSON并将其显示在地图视图上。 Everything is working except the last part. 除了最后一部分,其他所有东西都在工作。 I retrieve the GeoJSON, parse it to create a MKPolyline, give the line to my view (which is the map's delegate), and then I add the line to my mapView, but it doesn't show. 我检索了GeoJSON,将其解析以创建MKPolyline,将该行提供给我的视图(这是地图的委托),然后将其添加到我的mapView中,但未显示。 I am out of ideas on what can be going wrong. 我对可能出问题的地方一无所知。

I have a networking class that retrieves data from the server, and my view controller is its delegate. 我有一个从服务器检索数据的networking类,而我的视图控制器是它的委托。 It receives the line like this: 它收到这样的行:

-(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");
}

As you can see I've been printing information to find any mistakes. 如您所见,我一直在打印信息以查找任何错误。 Here is the output of the function: 这是函数的输出:

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

The view controller is properly set as the mapView's delegate, however, the method for rendering: 将视图控制器正确设置为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;
    }
}

never logs "hi" to the console! 永远不要在控制台上输入“ hi”! I even tried adding the deprecated method 我什至尝试添加过时的方法

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

to see if maybe it would work, but no luck. 看看是否可行,但没有运气。 Any help is appreciated, thank you. 任何帮助表示赞赏,谢谢。

EDIT: View controller declaration 编辑:查看控制器声明

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

This code was working fine. 这段代码工作正常。 The line was being painted on the map correctly, the problem was the code that parsed the coordinates and created the line. 该线已正确绘制在地图上,问题是解析坐标并创建线的代码。 It was setting the latitude and longitude backwards so the line was somewhere else in the world, invisible to my level of zoom. 它将纬度和经度向后设置,因此该线位于世界其他地方,对于我的缩放级别而言是不可见的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM