我有以下问题:
我有一个"绘制的地图"(图像),我作为叠加添加到MapView.有没有问题..但我需要的MapView限制在覆盖的区域,因此用户不能滚动/缩放这个区域之外..但它应该可以滚动/变焦的"边界内"覆盖 - 意味着我不能只为MapView禁用缩放/滚动.
关于这个主题有什么想法/解决方案吗?使用MapView/-Kit的原因是我需要将各种POI添加到自定义地图.仅使用ImageView + ScrollView呈现自定义地图时,这可能会变得更加复杂.
我已经研究了很多这个主题,但我没有找到一个很好的解决方案.
任何帮助表示赞赏!
最诚挚的问候,基督徒
编辑:这是我们的解决方案: 您提供了一个topleft和一个底部坐标来限制地图.(最小)缩放级别也是有限的.我已经停用减速功能,你可以从地图中弹出一点(为了更好的性能/ ux).我在叠加层上添加了一个〜1km的灰色边框,因此用户无法看到谷歌的原始世界地图.
LimitedMapView.h:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface LimitedMapView : MKMapView <UIScrollViewDelegate>{
}
@property (nonatomic, assign) CLLocationCoordinate2D topLeftCoordinate;
@property (nonatomic, assign) CLLocationCoordinate2D bottomRightCoordinate;
@end
Run Code Online (Sandbox Code Playgroud)
LimitedMapView.m:
#import "LimitedMapView.h"
@implementation LimitedMapView
@synthesize topLeftCoordinate, bottomRightCoordinate;
- (void)scrollViewDidZoom:(UIScrollView *)scrollView{
if([super respondsToSelector:@selector(scrollViewDidZoom:)]) [super scrollViewDidZoom:scrollView];
if ([self region].span.latitudeDelta > 0.002401f || [self region].span.longitudeDelta > 0.003433f) {
CLLocationCoordinate2D center = self.centerCoordinate;
MKCoordinateSpan span = MKCoordinateSpanMake(0.002401f, 0.003433f);
self.region = MKCoordinateRegionMake(center, span);
}
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if([super …Run Code Online (Sandbox Code Playgroud)