MkMapView缩放级别

时间:2010-04-26 10:09:40

标签: ios iphone objective-c mkmapview

我正在使用MkMapView和谷歌地图。我成功地用注释引脚显示地图视图和地址。但我想要增加缩放级别。如何以编程方式设置它?

-(void)showMyAddress
{

//Hide the keypad
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;

CLLocationCoordinate2D location = [self addressLocation];
region.span=span;
region.center=location;



if(addAnnotation != nil) {
    [mapView removeAnnotation:addAnnotation];
    [addAnnotation release];
    addAnnotation = nil;
}


addAnnotation = [[AddAnnotation alloc] initWithCoordinate:location ];
[addAnnotation setMTitle:@"abc"];
[addAnnotation setMSubTitle:@"def."]




[mapView addAnnotation:addAnnotation];

[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];


}


-(CLLocationCoordinate2D) addressLocation {
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
                       [@"abc" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];


NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSStringEncodingConversionAllowLossy  error:nil];
NSArray *listItems = [locationString componentsSeparatedByString:@","];

double latitude = 0.0;
double longitude = 0.0;

if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
    latitude = [[listItems objectAtIndex:2] doubleValue];
    longitude = [[listItems objectAtIndex:3] doubleValue];
}
else {

}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;

return location;
}

3 个答案:

答案 0 :(得分:13)

使span.longitudeDelta和span.latitudeDelta变小(即将其设置为0.02而不是0.2以进行10倍变焦)。

答案 1 :(得分:1)

试试这个好的教程,它帮助了我:
http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/

答案 2 :(得分:0)

此类别具有获取和设置缩放级别

https://github.com/jdp-global/MKMapViewZoom