2012-05-02 88 views
0

我正在過濾一些Google商家信息數據,然後在地圖視圖中顯示每個位置。目前我已將所有點顯示在地圖上。我需要弄清楚如何顯示annotationPoint.title = place.name;爲每個這些位置。如何在MapKit上顯示一組位置的註釋標題

任何想法如何去做這個整個陣列的位置?

非常感謝您的幫助!

//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]; 

     } 
    } 

回答

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


} 
+0

感謝。問題是我不知道該地區包含哪些城市或經緯度。它取決於用戶的位置和谷歌地方的搜索結果。 – hanumanDev

+0

然後通過特定城市有特定的經緯度直接或用戶當前位置經緯度。 – Dev