我想确定用户是否将地图移动了一定百分比(比如说 20%)。我怎样才能做到这一点?运动可以是任何方向。
问问题
250 次
1 回答
2
这是一个想法:
第一步:声明坐标属性
@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];
}
}
}
我敢肯定,实施可能会更干净,但只是为了让您入门,我认为这应该为您指明正确的方向。让我知道它是如何工作的!
于 2014-03-20T19:51:06.533 回答