[英]Setting the zoom level in MapKit Xcode
如何在SDK中设置Google MapKit的缩放级别? 例如,我住在纽约,我在ProjectName-info.plist(URL Types> Item 0> URL Schemes> Item 0)中设置了4个坐标位置,然后我在我的设置中设置了我的代码UIViewController子类文件:
#import "GoogleMap.h"
#import "MyAnnotation.h"
@implementation GoogleMap
- (void)viewDidLoad {
[super viewDidLoad];
variable1 = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"NewYorkAreas"
ofType:@"plist"]];
double minLat = [[variable1 valueForKeyPath:@"@min.latitude"] doubleValue];
double maxLat = [[variable1 valueForKeyPath:@"@max.latitude"] doubleValue];
double minLon = [[variable1 valueForKeyPath:@"@min.longitude"] doubleValue];
double maxLon = [[variable1 valueForKeyPath:@"@max.longitude"] doubleValue];
MKCoordinateRegion region;
region.center.latitude = (maxLat + minLat) / 2.0;
region.center.longitude = (maxLon + minLon) / 2.0;
region.span.latitudeDelta = (maxLat - minLat) * 1.05;
region.span.longitudeDelta = (maxLon - minLon) * 1.05;
map.region = region;
for (NSDictionary *newYorkAreasDict in variable1){
MyAnnotation *annotation = [[MyAnnotation alloc] initWithDictionary:newYorkAreasDict];
[map addAnnotation:annotation];
[annotation release];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
if (map.userLocation == annotation){
return nil;
}
NSString *identifier = @"MY_IDENTIFIER";
MKAnnotationView *annotationView = [map dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil){
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:identifier]
autorelease];
annotationView.image = [UIImage imageNamed:@"logo.png"];
annotationView.canShowCallout = YES;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
return annotationView;
}
所以这就是我现在在我的代码中所拥有的一切,当我运行和调试应用程序时,它完美地工作,并向我显示我在一个良好的缩放级别设置的所有4个区域的位置,但现在我只想要设置1个区域,所以当我擦除其他3个区域并运行它时只给我一个区域时,缩放级别似乎非常接近地图:
所以当代码修复时(假设有人帮我修改了缩放级别的代码),下次运行时,当我点击“在谷歌地图上找到我们”时,我的谷歌地图开放页面缩放级别应该看起来像这个:
所以,当我开始打开谷歌地图时,希望有人可以帮助我修复这个缩放级别,谢谢!
(关于纽约变量名,忘记了,我不住在纽约哈哈)
为latitudeDelta和longitudeDelta设置最小值。 我会做这样的事情:
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake((maxLat + minLat) / 2.0, (maxLon + minLon) / 2.0), 1000.0, 1000.0);
region.span.latitudeDelta = MAX(region.span.latitudeDelta, (maxLat - minLat) * 1.05);
region.span.longitudeDelta = MAX(region.span.longitudeDelta, (maxLon - minLon) * 1.05);
第一行创建一个具有1km乘1km矩形的区域,如果点扩展得更远,则以下行放大矩形。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.