Trigger based on coordinates

Hi there,

Apologies in advance for my lack of knowledge. I’m trying to write a small piece of code to change the colour of phone screen when a certain coordinates are reached. Code is not compiling and would really appreciate any help anyone can give me!

Thank you.

- (instancetype)initWithX:(double)x
        didUpdatePosition:(EILOrientedPoint *)position {
    EILPoint *corner1 = [[EILPoint alloc] initWithX:1 y:10]; 
    EILPoint *corner2 = [[EILPoint alloc] initWithX:6 y:1]; 
    if ([position distanceToPoint:corner1] < 2) {
        self.view.backgroundColor = [UIColor yellowColor];
    else if ([position distanceToPoint:corner2] < 2) {
        self.view.backgroundColor = [UIColor redColor];
        else {self.view.backgroundColor = [UIColor blackColor];}

Sharing the error message you’re getting would help a lot :slight_smile:

Also, any reason this code is not in the actual indoorLocationManager:didUpdatePosition delegate method?

Apologies for not including the error message last time! I have a similar question again. I’m wanting to create a trigger based on coordinates.

Below is my current code which locates the phone within the space and also sets up a switch button to operate the torch.

I’m wanting to only turn the torch on in certain areas within the space. So I tried disabling the button when in a certain area but am getting consistent error messages about undeclared variables. I feel there is a simple solution to this issue but I cannot seem to find it! Any help would be greatly, greatly appreciate. Thank you :slight_smile:


#import "ViewController.h"
#import "EstimoteSDK/ESTConfig.h"
#import "EILIndoorLocationManager.h"
#import "EILRequestFetchLocation.h"
#import "EILOrientedPoint.h"

@interface ViewController () <EILIndoorLocationManagerDelegate>
@property (nonatomic) EILIndoorLocationManager *locationManager;
@property (nonatomic) EILLocation *location;
@property (nonatomic) UISwitch *switchValue;

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.locationManager = [EILIndoorLocationManager new];
    self.locationManager.delegate = self;
    [ESTConfig setupAppID:@"XXX" andAppToken:@"XXX"];
    EILRequestFetchLocation *fetchLocationRequest =
    [[EILRequestFetchLocation alloc] initWithLocationIdentifier:@"XXX"];
    [fetchLocationRequest sendRequestWithCompletion:^(EILLocation *location,
                                                      NSError *error) {
        if (location != nil) {
            self.location = location;
            [self.locationManager startPositionUpdatesForLocation:self.location];
        } else {
            NSLog(@"can't fetch location: %@", error);

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

-    (void)indoorLocationManager:(EILIndoorLocationManager *)manager
didFailToUpdatePositionWithError:(NSError *)error {
    NSLog(@"failed to update position: %@", error);

- (void)indoorLocationManager:(EILIndoorLocationManager *)manager
            didUpdatePosition:(EILOrientedPoint *)position
                   inLocation:(EILLocation *)location {
    NSString *accuracy;
    switch (positionAccuracy) {
        case EILPositionAccuracyVeryHigh: accuracy = @"+/- 1.00m"; break;
        case EILPositionAccuracyHigh:     accuracy = @"+/- 1.62m"; break;
        case EILPositionAccuracyMedium:   accuracy = @"+/- 2.62m"; break;
        case EILPositionAccuracyLow:      accuracy = @"+/- 4.24m"; break;
        case EILPositionAccuracyVeryLow:  accuracy = @"+/- ? :-("; break;
        case EILPositionAccuracyUnknown:  accuracy = @"unknown"; break;
    NSLog(@"x: %5.2f, y: %5.2f, orientation: %3.0f, accuracy: %@",
          position.x, position.y, position.orientation, accuracy);

- (void)setTorchOn:(BOOL)isOn
    AVCaptureDevice* device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    [device lockForConfiguration:nil];
    [device setTorchMode:isOn ? AVCaptureTorchModeOn : AVCaptureTorchModeOff];
    [device unlockForConfiguration];

    UISwitch *switchValue = (UISwitch*)sender;
    [self setTorchOn:[switchValue isOn]];