我有一个使用 Google 地图 SDK 的应用程序。如果用户在地图视图控制器上进行疯狂滑动(比如 100 英里),那么我想将用户带回他当前的位置。
如何在地图中实现此功能?
如何在屏幕上追踪将地图移动 100 英里的疯狂滑动?
如何知道滑动的强度?以及根据缩放级别从当前位置滑动多少英里?
提前致谢!
我有一个使用 Google 地图 SDK 的应用程序。如果用户在地图视图控制器上进行疯狂滑动(比如 100 英里),那么我想将用户带回他当前的位置。
如何在地图中实现此功能?
如何在屏幕上追踪将地图移动 100 英里的疯狂滑动?
如何知道滑动的强度?以及根据缩放级别从当前位置滑动多少英里?
提前致谢!
你说的狂扫是什么意思?一次滑动即可将地图移动 100 英里?如果是这样,您可以UIPanGestureRecognizer在地图视图中添加一个,
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:aGMSMapView action:@selector(pan:)];
[aGMSMapView addGestureRecognizer:panRecognizer];
并实现一种方法来检测平移手势的状态是否为结束。如果是这样,请检查地图视图的中心以确定您移动了多远
-(void)pan:(UIPanGestureRecognizer*) gestureRecognizer
{
if(gestureRecognizer.state == UIGestureRecognizerStateEnded)
{
//get the center of map view, and calculate distance
CGPoint *point = aGMSMapView.center;
CLLocationCoordinate2D coor = [aGMSMapView.projection coordinateForPoint:point];
CLLocation *mapCenter = [[CLLocation alloc]initWithLatitude:coor.latitude longitude:coor.longitude];
CLLocationDistance d = [mapCenter distanceFromLocation:currentLocation];
if (d>= 106900)
{
//move your map view and do whatever you want...
}
}
}