MkMapView 缩放级别

发布于 2024-08-30 06:01:34 字数 1607 浏览 5 评论 0原文

我正在将 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;
}

I m using MkMapView with google maps.I succeed to show map view and address with annotation pin.But I want increased zoom level.How Can I Set it programmatically????

-(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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末が日狂欢 2024-09-06 06:01:34

使 span.longitudeDelta 和 span.latitudeDelta 变小(即将其设置为 0.02 而不是 0.2,以获得 10 倍缩放)。

Make the span.longitudeDelta and span.latitudeDelta smaller (i.e. set it to 0.02 instead of 0.2 to have a 10X zoom).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文