1

I want to determine if a User moved the map by a certain percentage (lets say 20%). How may I achieve this? The movement can be in any direction.

ilight
  • 1,622
  • 2
  • 22
  • 44

1 Answers1

2

Here's an idea:

Step 1: Declare coordinate property

@property CLLocationCoordinate2D lastCoordinate;

Step 2: On map launch, run this:

_lastCoordinate = [map convertPoint:self.view.center toCoordinateFromView:yourMap];

Step 3: Monitor

- (void) mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    CGPoint currentPoint = [mapView convertCoordinate:_lastCoordinate toPointToView:self.view];

    int xDistance = currentPoint.x - self.view.center.x;
    if (xDistance < 0) xDistance = xDistance * -1;

    if (xDistance > (self.view.bounds.size.width / 5)) {
        // moved 20% on x axis
        _lastCoordinate = [mapView convertPoint:self.view.center toCoordinateFromView:self.view];
    }
    else {
        int yDistance = currentPoint.y - self.view.center.y;
        if (yDistance < 0) yDistance = yDistance * -1;

        if (yDistance > (self.view.bounds.size.height / 5)) {
            // moved 20% on y axis
            _lastCoordinate = [mapView convertPoint:self.view.center 
                               toCoordinateFromView:self.view];
        }
    }
}

I'm sure implementation could be a touch cleaner, but just to get you started, I think this should point you in the right direction. Let me know how it works!

Logan
  • 52,262
  • 20
  • 99
  • 128