-1

我有MapView,在其中我在钦奈地区添加了一些 5 注释。我想在 MapView 开始加载后立即缩小钦奈,以便注释清晰可见。在 viewDidLoad 中:

CLLocationCoordinate2D location6;
    location6.latitude=12.9758;
    location6.longitude=80.2205;
    MapAnnotation *ann6=[[MapAnnotation alloc]initWithTitle:@"Chennai-Velacherry" andCoordinate:location6];
    [mapView addAnnotation:ann6];

     CLLocationCoordinate2D centerlocation;
    centerlocation.longitude=13.0810;
    centerlocation.longitude=80.2740;


    [mapView setCenterCoordinate:centerlocation animated:NO];
     [self.view addSubview:mapView];
4

4 回答 4

0

您不能有一组预定义的缩放级别。相反,您可以设置MKMapViewusing的可见区域MKCoordinateRegion此处提供示例代码。

于 2012-09-06T09:03:37.133 回答
0

You can do that like this:

Create a function like :

-(void)zoomToFitMapAnnotations:(MKMapView*)mv {

CLLocationCoordinate2D topLeftCoord;

topLeftCoord.latitude = -90;

topLeftCoord.longitude = 180;

CLLocationCoordinate2D bottomRightCoord;
bottomRightCoord.latitude = 90;
bottomRightCoord.longitude = -180;

for(MKAnnotations* annotation in mv.annotations)
{
   topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
   topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);

   bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
   bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
}

MKCoordinateRegion region;
region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; // Add a little extra space on the sides
region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; // Add a little extra space on the sides

region = [mv regionThatFits:region];
[mv setRegion:region animated:YES];

}

And call this function in viewDidLoad after all the pins are plotted

于 2012-09-06T09:08:07.970 回答
0

Try this

#define kMAPSPAN 1600

MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 1*kMAPSPAN, 1*kMAPSPAN);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
[_mapView setRegion:adjustedRegion animated:YES]; 

mapView is your MKMapView object and kMAPSPAN can be set according to your need and zoomLocation is your coordinate2D location for chennai

于 2012-09-06T09:09:07.733 回答
0

用这个,

        MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
        region.center.latitude = [currentPlace.latitude doubleValue];
        region.center.longitude = [currentPlace.longitude doubleValue];
        region.span.longitudeDelta = 0.03f; 
        region.span.latitudeDelta = 0.03f;
        [mapView setRegion:region animated:YES]; 
        [mapView setDelegate:self];
        mapView.zoomEnabled = YES;
        mapView.scrollEnabled = NO;

这些会改变你的缩放级别,

        region.span.longitudeDelta = 0.03f; 
        region.span.latitudeDelta = 0.03f;
于 2012-09-06T09:14:28.383 回答