【问题标题】:How to determine if a User moved the map MKMapView by certain percentage?如何确定用户是否将地图 MKMapView 移动了一定百分比?
【发布时间】:2014-03-20 19:10:08
【问题描述】:

我想确定用户是否将地图移动了一定百分比(比如说 20%)。我怎样才能做到这一点?运动可以是任何方向。

【问题讨论】:

    标签: ios mkmapview cllocationdistance


    【解决方案1】:

    这是一个想法:

    第一步:声明坐标属性

    @property CLLocationCoordinate2D lastCoordinate;
    

    第 2 步:在地图启动时,运行以下命令:

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

    第 3 步:监控

    - (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];
            }
        }
    }
    

    我确信实现可能会更干净,但为了让您开始,我认为这应该为您指明正确的方向。告诉我它是如何工作的!

    【讨论】:

      猜你喜欢
      • 2011-07-30
      • 2016-01-29
      • 1970-01-01
      • 2013-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      相关资源
      最近更新 更多