简体   繁体   English

在MapKit Xcode中设置缩放级别

[英]Setting the zoom level in MapKit Xcode

How can I set the zoom level of my Google MapKit in SDK? 如何在SDK中设置Google MapKit的缩放级别? Like for example, I live in New York, and I've set up 4 coordinate positions in my ProjectName-info.plist (URL Types > Item 0 > URL Schemes > Item 0), then I've set up my code in my UIViewController subclass file: 例如,我住在纽约,我在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;
    }

So this is all I have for now in my code, which works perfectly when I run and debug the app, and shows me the location of all 4 areas that I set in a good zooming level, but now I want only 1 area to set, so when I erased the other 3 area and when running it and only giving me one area, the zooming level seems very close to the map: 所以这就是我现在在我的代码中所拥有的一切,当我运行和调试应用程序时,它完美地工作,并向我显示我在一个良好的缩放级别设置的所有4个区域的位置,但现在我只想要设置1个区域,所以当我擦除其他3个区域并运行它时只给我一个区域时,缩放级别似乎非常接近地图:

在此输入图像描述

So I when the code is fixed (assuming someone helped me fix the code for the zooming level), the next time I run it, when I click on "Find us on Google Map", my Google Map opening page zoom level should look like this: 所以当代码修复时(假设有人帮我修改了缩放级别的代码),下次运行时,当我点击“在谷歌地图上找到我们”时,我的谷歌地图开放页面缩放级别应该看起来像这个: 在此输入图像描述

So yea hopefully someone can help me fix this zooming level when I begin opening Google Map, thanks! 所以,当我开始打开谷歌地图时,希望有人可以帮助我修复这个缩放级别,谢谢!

(About the New York variable names, forget it, I don't live in New York lol) (关于纽约变量名,忘记了,我不住在纽约哈哈)

Set a minimum value for latitudeDelta and longitudeDelta. 为latitudeDelta和longitudeDelta设置最小值。 I would do it something like this: 我会做这样的事情:

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);

The first line creates a region with a 1km by 1km rectangle, and the following lines enlarge the rectangle if the points are spread farther. 第一行创建一个具有1km乘1km矩形的区域,如果点扩展得更远,则以下行放大矩形。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM