Mapkit und sich aktualisierende Overlays

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Mapkit und sich aktualisierende Overlays

    Hallo zusammen.

    Ich habe hier folgende Situation. Ich lade ein Datenfile von VATSIM herunter, welches Flugzeuge und deren Bewegung auf der Map anzeigt. Die Flieger werden angezeigt, die Daten sind überliefert, soweit so gut.

    Nur habe ich das Problem, dass sich die Karte nicht aktualisiert. Nach meinem Verständnis muss dafür das File alle 180 Sekunden runtergeladen werden (VATSIM sagt maximal alle 2 Minuten), und die Karte muss nach dem erneuten download neu gerendert werden.

    Hier mal mein Code:

    Quellcode

    1. ​// Get the VATSIM status textfile
    2. NSURL *url = [NSURL URLWithString:@"http://status.vatsim.net/status.txt"];
    3. NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData
    4. timeoutInterval:0.0];
    5. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    6. [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
    7. {
    8. if (error)
    9. {
    10. // Failed to get the vatsim status file
    11. // show the error
    12. [[[UIAlertView alloc] initWithTitle:@"Error!"
    13. message:@"Could not retrieve the VATSIM traffic data file"
    14. delegate:self
    15. cancelButtonTitle:@"OK"
    16. otherButtonTitles:nil]
    17. show];
    18. NSLog(@"Error retrieving the VATSIM traffic data file");
    19. }
    20. else
    21. {
    22. _VatsimWhazzupUrls = [NSMutableArray array];
    23. NSString *statusFile = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
    24. NSArray *statusFileLines = [statusFile componentsSeparatedByString:@"\r\n"];
    25. for (NSString *line in statusFileLines) {
    26. if ([line hasPrefix:@"url0="])
    27. {
    28. NSString *whazzupUrl = [line substringFromIndex:5];
    29. [_VatsimWhazzupUrls addObject:whazzupUrl];
    30. NSLog(@"New status.txt url: %@", whazzupUrl); //Debugging
    31. }
    32. }
    Alles anzeigen


    Und hier der code fürs rendern der Karte.

    Quellcode

    1. ​//Call loadVatsimData from PlaneModelObject
    2. //(This can be done synchronously as we are currently on a different thread)
    3. PlaneModelObject *PMVC = [[PlaneModelObject alloc] init];
    4. [PMVC loadVatsimDataWithUrls:_VatsimWhazzupUrls];
    5. [_worldMapView addAnnotations:PMVC.trafficData];


    Leider ist es so, dass da nichts wiederholt wird, da auch kein entsprechender Code vorhanden ist. Habe nun viel gelesen, und meine zu verstehen, dass das über NSTimer laufen müsste. Nur leider bin ich da etwas überfordert, und wäre dankbar, wenn mir da jemand bei der Implementierung helfen könnte...

    Beste Grüsse,

    Stephan
    MacBook Pro 16" M2 Max 32 GB RAM, - iPad Pro 12.9" M1 256 GB WiFi+Cellular - iPhone 14 Pro 256 GB - Apple Watch Ultra