# Add live data

> **Note (legacy): A newer version of the Maps SDK is available**
> 
> This page uses v6.4.1 of the Mapbox Maps SDK. A newer version of the SDK is available. Learn about the latest version, v11.31.0, in the [Maps SDK documentation](https://docs.mapbox.com/ios/ja/maps/guides/).

Your browser doesn't support HTML5 video. Open [link to the video](https://docs.mapbox.com/ios/ja/ios/ja/assets/medias/LiveDataExample-ee0c009c5e9e1148accabdc92b44442b.mp4).

**Swift**

Title: `ViewController`

[View on GitHub](https://github.com/mapbox/ios-sdk-examples/tree/298e050be7352eb28cee6f03e02945593140c1f3/Examples/Swift/LiveDataExample.swift)

```swift
import Mapbox

class LiveDataExample: UIViewController, MGLMapViewDelegate {

    var source: MGLShapeSource!
    var timer = Timer()
    override func viewDidLoad() {
        super.viewDidLoad()

        // Create a new map view using the Mapbox Dark style.
        let mapView = MGLMapView(frame: view.bounds,
                                 styleURL: MGLStyle.darkStyleURL(withVersion: 9))
        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        mapView.tintColor = .gray

        // Set the map view‘s delegate property.
        mapView.delegate = self
        view.addSubview(mapView)
    }

    func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
        if let url = URL(string: "https://wanderdrone.appspot.com/") {
            // Add a source to the map. https://wanderdrone.appspot.com/ generates coordinates for simulated paths.
            source = MGLShapeSource(identifier: "wanderdrone", url: url, options: nil)
            style.addSource(source)

            // Add a Maki icon to the map to represent the drone's coordinate. The specified icon is included in the Mapbox Dark style's sprite sheet. For more information about Maki icons, see https://www.mapbox.com/maki-icons/
            let droneLayer = MGLSymbolStyleLayer(identifier: "wanderdrone", source: source)
            droneLayer.iconImageName = NSExpression(forConstantValue: "rocket-15")
            droneLayer.iconHaloColor = NSExpression(forConstantValue: UIColor.white)
            style.addLayer(droneLayer)

            // Create a timer that calls the `updateUrl` function every 1.5 seconds.
            timer.invalidate()
            timer = Timer.scheduledTimer(timeInterval: 1.5, target: self, selector: #selector(updateUrl), userInfo: nil, repeats: true)
        }
    }

    @objc func updateUrl() {
        // Update the icon's position by setting the `url` property on the source.
        source.url = source.url
    }

    override func viewWillDisappear(_ animated: Bool) {
        // Invalidate the timer if the view will disappear.
        timer.invalidate()
        timer = Timer()
    }
}
```

**Objective C**

Title: `ViewController`

[View on GitHub](https://github.com/mapbox/ios-sdk-examples/tree/298e050be7352eb28cee6f03e02945593140c1f3/Examples/ObjectiveC/LiveDataExample.m)

```swift

#import "ViewController.h"
@import Mapbox;
@interface ViewController () <MGLMapViewDelegate>

@property (nonatomic, strong, nullable) NSTimer *timer;
@property MGLShapeSource *source;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Create a new map view using the Mapbox Dark style.
    MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds styleURL:[MGLStyle darkStyleURL]];
    mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    mapView.tintColor = [UIColor darkGrayColor];
    
    // Set the map view‘s delegate property.
    mapView.delegate = self;
    
    [self.view addSubview:mapView];
}

- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {
    // Add a source to the map. https://wanderdrone.appspot.com/ generates coordinates for simulated paths.
    NSURL *url = [NSURL URLWithString:@"https://wanderdrone.appspot.com/"];
    _source = [[MGLShapeSource alloc] initWithIdentifier:@"wanderdrone" URL:url options:nil];
    [style addSource:_source];
    
    // Add a Maki icon to the map to represent the drone's coordinate. The specified icon is included in the Mapbox Dark style's sprite sheet. For more information about Maki icons, see https://www.mapbox.com/maki-icons/
    MGLSymbolStyleLayer *droneLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"wanderdrone" source:_source];
    droneLayer.iconImageName = [NSExpression expressionForConstantValue:@"rocket-15"];
    [style addLayer:droneLayer];
    
    // Create a timer that calls the `updateUrl` function every 1.5 seconds.
    [_timer invalidate];
    _timer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(updateURL) userInfo:nil repeats:YES];
}

- (void)updateURL {
    // Update the icon's position by setting the `url` property on the source.
    _source.URL = _source.URL;
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    // Invalidate the timer if the view will disappear.
    [_timer invalidate];
    _timer = nil;
}

@end
```