2

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

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];

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

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

任何人都可以有一个想法吗?

谢谢

4

1 回答 1

1

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

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];

要进一步放大,请减小度数跨度的大小,例如:

MKCoordinateSpan degreeSpan = MKCoordinateSpanMake(0.05, 0.05);

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

MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(currentLocation.coordinate, 1000, 1000);

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

于 2016-08-26T05:16:23.653 回答