首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MKMapView setVisibleMapRect第一次不工作

问MKMapView setVisibleMapRect第一次不工作
EN

Stack Overflow用户
提问于 2016-08-17 16:42:07
回答 1查看 995关注 0票数 2

我已经实现了双击缩放使用以下代码。

代码语言:javascript
复制
CLLocation* currentLocation = [myArray objectAtIndex:5];
MKMapPoint annotationPoint =  MKMapPointForCoordinate(currentLocation.coordinate);
MKMapRect zoomRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0.1, 0.1);
[mapView setVisibleMapRect:zoomRect animated:YES];

当我第一次双击时,缩放到特定的引脚位置不工作,下一次工作正常。

如果从离引脚位置很远的不同位置双击,那么同样的问题,即缩放到特定引脚位置不起作用。

有谁能有个主意吗?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-08-26 13:16:24

要使地图以坐标居中并缩小以显示坐标两侧的某些经度和纬度,请创建一个MKCoordinateRegion对象并更新MKMapView以显示新区域:

代码语言:javascript
复制
CLLocation* currentLocation = [myArray objectAtIndex:5];
// Create a span covering 0.1 degrees east to west and north to south
MKCoordinateSpan degreeSpan = MKCoordinateSpanMake(0.1, 0.1);
// Create a region that centers the span on currentLocation
MKCoordinateRegion region = MKCoordinateRegionMake(currentLocation.coordinate, degreeSpan);
// Update the map to show the new region
[mapView setRegion:region animated:YES];

要进一步放大,请缩小度数范围的大小,例如:

代码语言:javascript
复制
MKCoordinateSpan degreeSpan = MKCoordinateSpanMake(0.05, 0.05);

您还可以创建以米为单位的区域,这可以更容易地推断。下面创建了一个1000 x 1000米的区域:

代码语言:javascript
复制
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(currentLocation.coordinate, 1000, 1000);

若要进一步放大,请减少米的数量。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38991899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档