使用MKDirectionsRequest的MKMapView没有绘制任何东西

时间:2015-01-16 15:09:16

标签: ios objective-c mkmapview mkoverlay

这是我必须向一个位置绘制路线的代码,就像普通iPhone映射应用程序一样。

-(void)initUserCoords{


    //NSLog(@"This if from new %@ %@", self.latitude, self.longitude);



    double dLat = 59.2462;
    double dLong = 15.1679;

    MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(dLat, dLong) addressDictionary:nil];
    MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];

    MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];

    request.source = [MKMapItem mapItemForCurrentLocation];

    request.destination = mapItem;
    request.requestsAlternateRoutes = YES;
    MKDirections *directions =
    [[MKDirections alloc] initWithRequest:request];

    [directions calculateDirectionsWithCompletionHandler:
 ^(MKDirectionsResponse *response, NSError *error) {
         if (error) {
             // Handle Error
         } else {
             [self showRoute:response];
         }
     }];

    }

-(void)showRoute:(MKDirectionsResponse *)response
{
    for (MKRoute *route in response.routes)
    {
        [self.mapView
         addOverlay:route.polyline level:MKOverlayLevelAboveRoads];
    }
}

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id < MKOverlay >)overlay
{
    MKPolylineRenderer *renderer =
    [[MKPolylineRenderer alloc] initWithOverlay:overlay];
    renderer.strokeColor = [UIColor blueColor];
    renderer.lineWidth = 5.0;
    return renderer;
}

现在的问题是没有任何东西被绘制出来。当应用程序运行时,我的位置正在显示但之后没有任何反应。我感谢任何帮助,谢谢!

0 个答案:

没有答案