ฉันจะตั้งค่าระดับการซูมของ Google MapKit ใน SDK ได้อย่างไร ตัวอย่างเช่น ฉันอาศัยอยู่ในนิวยอร์ก และฉันได้ตั้งค่าตำแหน่งพิกัด 4 ตำแหน่งใน ProjectName-info.plist ของฉัน (ประเภท URL > รายการ 0 > แบบแผน URL > รายการ 0) จากนั้นฉันได้ตั้งค่ารหัสของฉันใน ไฟล์คลาสย่อย 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 แห่งและเมื่อเรียกใช้และให้ฉันพื้นที่เดียว ระดับการซูมจึงดูใกล้เคียงกับแผนที่มาก:
ดังนั้น เมื่อโค้ดได้รับการแก้ไขแล้ว (สมมติว่ามีคนช่วยแก้ไขโค้ดในระดับการซูม) ครั้งต่อไปที่เรียกใช้งาน เมื่อฉันคลิก "ค้นหาเราบน Google Map" ระดับการซูมหน้าเปิด Google Map ของฉันควรมีลักษณะดังนี้ นี้:
ใช่แล้ว หวังว่าจะมีคนช่วยฉันแก้ไขระดับการซูมนี้เมื่อฉันเริ่มเปิด Google Map ขอบคุณ
(เกี่ยวกับชื่อตัวแปร New York ลืมไปเถอะ ฉันไม่ได้อาศัยอยู่ใน New York 555)