Get User Location (iOS)

This article describes how to get the user's location using the iOS SDK.

Get User Location

MRLocationManager determines the user's location by gathering all the available location data for your Meridian-powered app. The MRLocationManagerDelegate protocol will make sure that you get callbacks as new locations are determined.

    // In a view controller that adopts the MRLocationManagerDelegate protocol
    // Assume we have properties called appKey and locationManager

    - (void)viewDidLoad {
        [super viewDidLoad];

        self.appKey = [MREditorKey keyWithIdentifier:@"5085468668573440"];
        self.locationManager = [[MRLocationManager alloc] initWithApp:self.appKey];
        self.locationManager.delegate = self;

    // You may want to start getting location updates here
    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];

        [self.locationManager startUpdatingLocation];

    // And you may want to stop getting location updates here
    - (void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];

        [self.locationManager stopUpdatingLocation];

    // Implementing MRLocationManagerDelegate methods
    - (void)locationManager:(MRLocationManager *)manager didUpdateToLocation:(MRLocation *)location {
        NSLog(@"New location: %@", location);

    - (void)locationManager:(MRLocationManager *)manager didFailWithError:(NSError *)error {
        NSLog(@"Location error: %@", error);