0

我正在过滤一些 Google Places 数据,然后在地图视图上显示每个位置。目前我的所有点都显示在地图上。我需要弄清楚如何显示annotationPoint.title = place.name; 对于这些位置中的每一个。

知道我将如何为整个位置数组执行此操作吗?

非常感谢您的帮助!

 //UPDATE - to handle filtering
    - (void)googlePlacesConnection:(GooglePlacesConnection *)conn didFinishLoadingWithGooglePlacesObjects:(NSMutableArray *)objects 
    {

        if ([objects count] == 0) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No matches found near this location" 
                                                            message:@"Try another place name or address" 
                                                           delegate:nil 
                                                  cancelButtonTitle:@"OK" 
                                                  otherButtonTitles: nil];
            [alert show];
        } else {
            locations = objects;
            //UPDATED locationFilterResults for filtering later on
            locationsFilterResults = objects;
            [tableView reloadData];

            [mapView removeAnnotations:mapView.annotations];
            [mapView addAnnotations:objects];

        }
    }
4

1 回答 1

0

试试这个代码:

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-02T10:54:24.857 回答