How can I set the zoom level of my Google MapKit in SDK? Like for example, I live in New York, and I've set up 4 co开发者_如何学JAVAordinate 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:
#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:
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. 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.
精彩评论