試試這個代碼:
if ([myArr containsObject:@"Germany"])
{
gerArr = [[NSMutableArray alloc]init];
[gerArr addObject:@"Berlin"];
[gerArr addObject:@"Dresden"];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 52.524268 ;
region.center.longitude = 13.40629;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
DisplayMap *gann = [[DisplayMap alloc] init];
gann.title = @"Berlin";
gann.subtitle = @"Germany";
gann.coordinate = region.center;
[mapView addAnnotation:gann];
MKCoordinateRegion region1 = { {0.0, 0.0 }, { 0.0, 0.0 } };
region1.center.latitude = 51.050991 ;
region1.center.longitude = 13.733634;
region1.span.longitudeDelta = 0.01f;
region1.span.latitudeDelta = 0.01f;
[mapView setRegion:region1 animated:YES];
DisplayMap *gann1 = [[DisplayMap alloc] init];
gann1.title = @"Dresden";
gann1.subtitle = @"Germany";
gann1.coordinate = region1.center;
[mapView addAnnotation:gann1];
MKCoordinateRegion region2 = { {0.0, 0.0 }, { 0.0, 0.0 } };
region2.center.latitude = 50.111445 ;
region2.center.longitude = 8.680615;
region2.span.longitudeDelta = 0.01f;
region2.span.latitudeDelta = 0.01f;
[mapView setRegion:region2 animated:YES];
DisplayMap *gann2 = [[DisplayMap alloc] init];
gann2.title = @"Frankfurt";
gann2.subtitle = @"Germany";
gann2.coordinate = region2.center;
[mapView addAnnotation:gann2];
}
else if([myArr containsObject:@"Austria"])
{
ausArr = [[NSMutableArray alloc]init];
[ausArr addObject:@"Vienna"];
[ausArr addObject:@"Danube River"];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 48.208174 ;
region.center.longitude = 16.373819;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
DisplayMap *ausann = [[DisplayMap alloc] init];
ausann.title = @"Vienna";
ausann.subtitle = @"Austria";
ausann.coordinate = region.center;
[mapView addAnnotation:ausann];
MKCoordinateRegion region1 = { {0.0, 0.0 }, { 0.0, 0.0 } };
region1.center.latitude = 48.266667 ;
region1.center.longitude = 16.366667;
region1.span.longitudeDelta = 0.01f;
region1.span.latitudeDelta = 0.01f;
[mapView setRegion:region1 animated:YES];
DisplayMap *ausann1 = [[DisplayMap alloc] init];
ausann1.title = @"Danube River";
ausann1.subtitle = @"Austria";
ausann1.coordinate = region1.center;
[mapView addAnnotation:ausann1];
}
來源
2012-05-02 10:54:24
Dev
感謝。問題是我不知道該地區包含哪些城市或經緯度。它取決於用戶的位置和谷歌地方的搜索結果。 – hanumanDev
然後通過特定城市有特定的經緯度直接或用戶當前位置經緯度。 – Dev