Рисование полилинии на карте не показывает - PullRequest
2 голосов
/ 16 ноября 2011

Я пытаюсь подключить мои контакты, используя MKPolyline на моем MKMapView. Это не дает ошибок, но линия не отображается на моей карте.

Я почти все перепробовал, но все равно не могу заставить его работать.

[NEW]

Я уже пытался комментировать все остальное. Я также переместил все в тот же контроллер. Дочерний объект только отправляет NSMutableArray с CLLocations своему родителю. Я также подумал, что он может рисовать на MKMapView, отличном от того, который отображается на экране. Но, похоже, нет, потому что я успешно рисую булавки и TileOverlay на том же MKMapView.

Я попробовал это безуспешно:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    NSLog(@"Drawing overlay");
    if(overlay == self.routeLine)
    {
        NSLog(@"Drawing routeLine");
        if(nil == self.routeLineView)
        {
            NSLog(@"Drawing routeLineView");
            NSLog(@"Point Count: %d",self.routeLine.pointCount);
            /*MKMapPoint *tmp = self.routeLine.points;
            for(int i = 0; i < self.routeLine.pointCount;i++)
                NSLog(@"Points: %d\t%@",i, tmp[i]);*/ // Can't find way to output points
            self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine] autorelease];
            self.routeLineView.fillColor = [UIColor redColor];
            self.routeLineView.strokeColor = [UIColor redColor];
            self.routeLineView.lineWidth = 3;
            NSLog(@"After setting line specs");
        }
        return self.routeLineView;
        NSLog(@"Not supposed to be called");
    }
    /*TileOverlayView *view = [[TileOverlayView alloc] initWithOverlay:overlay];
    view.tileAlpha = 0.6;
    return [view autorelease];*/
    return nil;
}

Это выводит:

Наложение рисунка
Рисование линии маршрута
Рисование routeLineView
Количество очков: 2
После установки спецификации линии


[Первый вопрос]

Я опубликую свой код в обратном порядке:

MAPview: viewForOverlay:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    NSLog(@"Drawing overlay");
    if(overlay == self.routeLine)
    {
         NSLog(@"Drawing routeLine");
         if(nil == self.routeLineView)
        {
            NSLog(@"Drawing routeLineView");
            self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine] autorelease];
            self.routeLineView.fillColor = [UIColor redColor];
            self.routeLineView.strokeColor = [UIColor redColor];
            self.routeLineView.lineWidth = 3;
        }
        return self.routeLineView;
    }
    //Not part of the Question
    TileOverlayView *view = [[TileOverlayView alloc] initWithOverlay:overlay];
    view.tileAlpha = 0.6;
    return [view autorelease];
}

Это выводит все на консоль:

Нанесение оверлея
Рисование линии маршрута
Рисование routeLineView

Добавление строки

-(void)addRouteLine:(MKPolyline *)route
{
    self.routeLine = route;
    NSLog(@"addRouteLine"); //Successfully prints in console
    [myMapView addOverlay:self.routeLine];
}

Создание строки Это происходит в дочернем модальном viewcontroller

-(void)loadRoute
{
    // while we create the route points, we will also be calculating the bounding box of our route
    // so we can easily zoom in on it.
    MKMapPoint northEastPoint;
    MKMapPoint southWestPoint;
    // create a c array of points.
    MKMapPoint *pointArr = malloc(sizeof(CLLocationCoordinate2D) * waypoints.count);
    MKPolyline *polyLine;
    for(int idx = 0; idx < waypoints.count; idx++)
    {
        CLLocationCoordinate2D coordinate = ((CLLocation *)[waypoints objectAtIndex:idx]).coordinate;

        MKMapPoint point = MKMapPointForCoordinate(coordinate);
        // if it is the first point, just use them, since we have nothing to compare to yet.
        if (idx == 0)
        {
            northEastPoint = point;
            southWestPoint = point;
        }
        else
        {
            if (point.x > northEastPoint.x)
                northEastPoint.x = point.x;
            if(point.y > northEastPoint.y)
                northEastPoint.y = point.y;
            if (point.x < southWestPoint.x)
                southWestPoint.x = point.x;
            if (point.y < southWestPoint.y)
                southWestPoint.y = point.y;
        }

        NSLog(@"Routing Waypoint:\t%f\t%f\t%.02f\t%.02f", point.x, point.y, coordinate.latitude, coordinate.longitude);
        pointArr[idx] = point;
    }

    // create the polyline based on the array of points.
    polyLine = [MKPolyline polylineWithPoints:pointArr count:(waypoints.count)];
    if([self.presentingViewController isKindOfClass:[FirstViewController class]])
        [(FirstViewController*)self.presentingViewController addRouteLine:polyLine];

    free(pointArr);
}

Это выводит данные правильно. В настоящее время у меня есть две «Маршрутные точки». Мой вывод был:

Маршрутная точка маршрута: 145449142.044444 161268376.039062 -34,07 15,06
Маршрутная точка маршрута: 142917646.563556 157564926.760068 -29,86 11,67

Это ясно указывает на то, что две точки являются действительными точками с фактическими координатами и т. Д.


Таким образом, он создает ломаную линию с правильными координатами. Вызывает метод для рисования этой полилинии. Затем он также достигает точки, в которой он добавляет полилинию в качестве представления.

Почему бы это не показать на карте? Пожалуйста, помогите!

...