gpt4 book ai didi

ios - MKMapRect 设置后如何缩小

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:08:12 25 4
gpt4 key购买 nike

我使用MKMapRectMake 标记东北和西南以显示区域。以下是我的做法:

routeRect = MKMapRectMake(southWestPoint.x, southWestPoint.y, northEastPoint.x - southWestPoint.x, northEastPoint.y - southWestPoint.y);
[self.mapView setVisibleMapRect:routeRect];

设置好这个显示区域后,如何把 map 缩小一点?执行此操作的最佳方法是什么?

更新

这是我用来为 setVisibleMapRect 函数获取 rect 的代码:

for(Path* p in ar)
{
self.routeLine = nil;
self.routeLineView = nil;

// while we create the route points, we will also be calculating the bounding box of our route
// so we can easily zoom in on it.
MKMapPoint northEastPoint;
MKMapPoint southWestPoint;

// create a c array of points.
MKMapPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) * ar.count);

for(int idx = 0; idx < ar.count; idx++)
{
Path *m_p = [ar objectAtIndex:idx];
[NSCharacterSet characterSetWithCharactersInString:@","]];



CLLocationDegrees latitude = m_p.Latitude;
CLLocationDegrees longitude = m_p.Longitude;

// create our coordinate and add it to the correct spot in the array
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);


MKMapPoint point = MKMapPointForCoordinate(coordinate);

// adjust the bounding box
// if it is the first point, just use them, since we have nothing to compare to yet.
if (idx == 0) {
northEastPoint = point;
southWestPoint = point;
}
else
{
if (point.x > northEastPoint.x)
northEastPoint.x = point.x;
if(point.y > northEastPoint.y)
northEastPoint.y = point.y;
if (point.x < southWestPoint.x)
southWestPoint.x = point.x;
if (point.y < southWestPoint.y)
southWestPoint.y = point.y;
}

pointArr[idx] = point;
}

// create the polyline based on the array of points.
self.routeLine = [MKPolyline polylineWithPoints:pointArr count:ar.count];

_routeRect = MKMapRectMake(southWestPoint.x, southWestPoint.y, northEastPoint.x - southWestPoint.x, northEastPoint.y - southWestPoint.y);
// clear the memory allocated earlier for the points
free(pointArr);


[self.mapView removeOverlays: self.mapView.overlays];
// add the overlay to the map
if (nil != self.routeLine) {
[self.mapView addOverlay:self.routeLine];
}

// zoom in on the route.
[self zoomInOnRoute];

}

最佳答案

试试这个:(编辑)

    MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.01;
span.longitudeDelta = 0.01;
CLLocationCoordinate2D zoomLocation = newLocation.coordinate;
region.center = zoomLocation;
region.span = span;
region = [mapViewObject regionThatFits:region];
[mapViewObject setRegion:region animated:NO];

关于ios - MKMapRect 设置后如何缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17922582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com