2

マップにポリラインを表示しようとしていますが、ラインが表示されません。いろいろ試してみましたが、メモはうまくいくようです。

Core Data 関数を確認したところ、データが返されているため、問題はありません。マップポイントの作成またはマップ上のドローイングのどこかにいる必要があります(推測します)。きっとどこかでちょっとした間違いに違いないのですが、見つけられません。

私のコード:

- (void)viewDidLoad
{
    [super viewDidLoad];

    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    mapView.delegate = self;
}

- (void)createLine
{
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *context = [appDelegate managedObjectContext];

    NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Logs" inManagedObjectContext:context];
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:entityDescription];

    NSError *error;
    NSArray *logs = [context executeFetchRequest:request error:&error];

    int logsCount = [logs count];
    MKMapPoint points[logsCount];

    // loop logs
    for (int i = 0; i < logsCount; i++)
    {
        MKMapPoint point;
        point = MKMapPointMake([[[logs objectAtIndex:i] valueForKey:@"lat"] doubleValue], [[[logs objectAtIndex:i] valueForKey:@"lng"] doubleValue]);

        points[i] = point;
    }

    MKPolyline *routeLine = [MKPolyline polylineWithPoints:points count:logsCount];
    [mapView addOverlay:routeLine];
}

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKOverlayView *mapOverlayView = [[MKOverlayView alloc] initWithOverlay:overlay];
    return mapOverlayView;
}
4

1 に答える 1