MKMapView缩放显示全部annotation(转)
原文 http://blog.csdn.net/favormm/article/details/8028026
#define MINIMUM_ZOOM_ARC 0.014 //approximately 1 miles (1 degree of arc ~= 69 miles)
#define ANNOTATION_REGION_PAD_FACTOR 1.15
#define MAX_DEGREES_ARC 360
//size the mapView region to fit its annotations
- (void)zoomMapViewToFitAnnotations:(MKMapView *)mapView animated:(BOOL)animated
{
NSArray *annotations = mapView.annotations;
int count = [mapView.annotations count];
if ( count == 0) { return; } //bail if no annotations //convert NSArray of id <MKAnnotation> into an MKCoordinateRegion that can be used to set the map size
//can't use NSArray with MKMapPoint because MKMapPoint is not an id
MKMapPoint points[count]; //C array of MKMapPoint struct
for( int i=0; i<count; i++ ) //load points C array by converting coordinates to points
{
CLLocationCoordinate2D coordinate = [(id <MKAnnotation>)[annotations objectAtIndex:i] coordinate];
points[i] = MKMapPointForCoordinate(coordinate);
}
//create MKMapRect from array of MKMapPoint
MKMapRect mapRect = [[MKPolygon polygonWithPoints:points count:count] boundingMapRect];
//convert MKCoordinateRegion from MKMapRect
MKCoordinateRegion region = MKCoordinateRegionForMapRect(mapRect); //add padding so pins aren't scrunched on the edges
region.span.latitudeDelta *= ANNOTATION_REGION_PAD_FACTOR;
region.span.longitudeDelta *= ANNOTATION_REGION_PAD_FACTOR;
//but padding can't be bigger than the world
if( region.span.latitudeDelta > MAX_DEGREES_ARC ) { region.span.latitudeDelta = MAX_DEGREES_ARC; }
if( region.span.longitudeDelta > MAX_DEGREES_ARC ){ region.span.longitudeDelta = MAX_DEGREES_ARC; } //and don't zoom in stupid-close on small samples
if( region.span.latitudeDelta < MINIMUM_ZOOM_ARC ) { region.span.latitudeDelta = MINIMUM_ZOOM_ARC; }
if( region.span.longitudeDelta < MINIMUM_ZOOM_ARC ) { region.span.longitudeDelta = MINIMUM_ZOOM_ARC; }
//and if there is a sample of 1 we want the max zoom-in instead of max zoom-out
if( count == 1 )
{
region.span.latitudeDelta = MINIMUM_ZOOM_ARC;
region.span.longitudeDelta = MINIMUM_ZOOM_ARC;
}
[mapView setRegion:region animated:animated];
} - (void)viewWillAppear:(BOOL)animated
{
[self zoomMapViewToFitAnnotations:self.mapView animated:animated];
//or maybe you would do the call above in the code path that sets the annotations array
}
MKMapView缩放显示全部annotation(转)的更多相关文章
- WPF通过鼠标滑轮缩放显示图片
如果你使用WinForm比较难实现通过滚动鼠标滑轮来对图片进行缩放显示,那么,你应该考虑一下使用WPF,既然是下一代Windows客户端开发平台,明显是有一定优势的,不然,MS是吃饱了撑着. 首先 ...
- Qt 图像缩放显示
1. QImage Image; Image.load(":/images/f1.png"); QPixmap pixmap = QPixmap::fromImage(Image) ...
- ASP.NET将原始图片按照指定尺寸等比例缩放显示图片
网站上可能会有很多图片,比如产品图片等,而且他们可能大小不一,宽度和高度也不一定一样,有的很大有的很小.如果放在一张网页上,可能会破坏版面,但是如果强制让他们按照指定的宽度和高度显示,因为比例不同还会 ...
- H5 canvas 解决合成图模糊(canvas真机下scale不起作用,无法缩放显示的问题)
在解决canvas合成图片模糊的问题想必我们已经了解了 window.devicePixelRatio window接口的devicePixelRatio返回当前显示设备的物理像素分辨率与C ...
- 手机端自适应缩放显示 js
<script> var _width = parseInt(window.screen.width); var scale = _width/640; var ua = navigato ...
- 【python】显示图片 并随意缩放图片大小 图片归一化
cv2.namedWindow("image_",0) cv2.imshow("image_",image)就可以随意缩放显示图片的窗口大小啦. ------ ...
- 百度地图API 级别自动缩放
今天做一个基于百度地图API的小项目 查了很长时间apid都没有找到地图呈现出来的时候地图按坐标的多少自动缩放显示的等级比例,特此记录笔记!var points = [point1, point2,p ...
- H5拖拽 构造拖拽及缩放 pdf展示
前言: 协助项目需要实现一个签名的功能. 功能说明:1.有文本签名和头像签名.2.头像签名需要实现可拖拽功能.3.需要展示的是pdf的文件并需要获取签名位于pdf文件的相对位置. 功能一:实现拖拽 思 ...
- sdl的缩放问题
SDL是一种既是开源的,也是跨平台的多媒体开发包,在各种平台上应用很广,经常和FFMPEG等解码器同时使用.对于在windows mobile等缺乏通用播放器的平台来说,是一种很好的选择.网上很多代码 ...
随机推荐
- 剑指offer 面试57题
面试57题: 题目:和为s的数字 题目描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 输出描述: 对应每个测 ...
- Google Cloud Platfrom中运行基础的Apache Web服务
Links: https://cloud.google.com/compute/docs/tutorials/basic-webserver-apache 步骤: 1.安装Apache 2.重写Apa ...
- jmeter 测试restful接口
jmeter 测试restful接口,JSON数据格式 1.添加线程组 2.添加HTTP信息头管理器 请求发送JSON数据格式参数,需要设置Content-Type为application/json ...
- 调用settings.py的配置信息作为全局使用
项目中一些比较零散的信息可以保存在数据库,也可以保存在settings.py里面 并且这些变量也可以像引用数据里面的数据使用, 可以把信息保存在settings.py里面,也可以保存在数据 ...
- Web Deploy 安装及问题解决
注意: 站点名称: 服务器上IIS的站点名称. . 我之前这里随便写一直不成功. 返回500..... 用户名, 密码: 这里最好用windows帐号. 问题比较少. 目标URL: 可不写. 可 ...
- oc字符串+数组+字典操作题目
1. 判断中间目录是否存在 (10分) 比如 传入字符串 @"/home/qianfeng/oc.txt" 和 @"qianfeng" 返回:YES 传入字符串 ...
- VC引用静态库
对于路径的设置: Tools->Options->Directory中设置的Lib路径,是给VC环境设置的, 所以只要是这个VC打开的项目,都会包含这些路径. Project->Se ...
- sublime text C++
几乎每一门编程语言都是从"Hello, world!"学起的, 刚学编程的时候感觉有点枯燥, 对它不够重视. 可是到后来慢慢发现, 几乎我学到的每一个知识点, 在最开始都是经过 h ...
- Kubernetes Kube-proxy
Kube-proxy主要负责Service的实现. kube-proxy enables the Kubernetes service abstraction by maintaining netwo ...
- IntelliJ Idea 快捷键精选
Alt+Enter,导入包,自动修正Ctrl+F,查找文本Alt+Up/Down,上/下移一行:在方法间快速移动定位:与光标位置有关Alt+Shift+Up,多次up可选中一行Ctrl+X,剪切行Ct ...