2012-01-26 49 views
0

對於iPad應用程序,我在SplitView上使用左側的TableView顯示餐廳列表。右側有一個MapView顯示這些餐館的註釋。在地圖視圖中突出顯示註釋

我想放大到一個註釋,並以某種方式突出顯示它,當用戶點擊左側表中的相關餐廳。

不幸的是我沒有得到地圖重新加載。

任何建議或想法如何解決這個問題?

這裏是我的viewDidLoad

- (void)viewDidLoad { 

    NSString *docsDir; 
    NSArray *dirPaths; 

    dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    docsDir = [dirPaths objectAtIndex:0]; 

    databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"smshipaddec2011.db"]]; 
    const char *dbpath = [databasePath UTF8String]; 

    MapViewAnnotation *newAnnotation; 

    sqlite3_stmt *statement; 

    if (sqlite3_open(dbpath, &smshdb2) == SQLITE_OK) { 

     NSString *querySQL = [NSString stringWithFormat: @"SELECT vmapx, vmapy, vname, vsection FROM SMSHVENUES"]; 

     const char *query_stmt = [querySQL UTF8String]; 

     if (sqlite3_prepare_v2(smshdb2, query_stmt, -1, &statement, NULL) == SQLITE_OK) { 

      while(sqlite3_step(statement) == SQLITE_ROW) { 

       double latitude = sqlite3_column_double(statement, 0); 
       double longitude = sqlite3_column_double(statement, 1); 

       CLLocationCoordinate2D location; 
       location.latitude = latitude; 
       location.longitude = longitude; 

       newAnnotation = [[MapViewAnnotation alloc] initWithTitle:[[NSString alloc] initWithUTF8String: 
                      (const char *) sqlite3_column_text(statement, 2)] andCoordinate:location]; 
       [mapView addAnnotation:newAnnotation]; 
       [newAnnotation release]; 

      } 

      sqlite3_finalize(statement); 

     } 

     sqlite3_close(smshdb2); 
    } 



    mapView.showsUserLocation = YES; 

    [mapView setMapType:MKMapTypeStandard]; 
    [mapView setZoomEnabled:YES]; 
    [mapView setScrollEnabled:YES]; 

    CLLocation *userLoc = mapView.userLocation.location; 
    CLLocationCoordinate2D userCoordinate = userLoc.coordinate; 

    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 

    //this is Shanghai: 
    region.center.latitude = 31.227849 ; 
    region.center.longitude = 121.473770; 

    region.span.longitudeDelta = 0.02f; 
    region.span.latitudeDelta = 0.02f; 

    [mapView setRegion:region animated:YES]; 

    [super viewDidLoad]; 

} 

現在,當有人點擊表格單元格「configureView」被觸發,工作正常。但後來我不知道如何移動地圖,放大到該註釋,也許改變顏色或使其變大。

- (void)configureView { 

    // animate map 
    // zoom to annotation 
    // make it bigger or change colour 

} 

真的很感謝任何幫助。

回答

1

的MKMapView具有簡單API此:

爲了響應用戶的選擇,你可以調用類似:

[MapView的setRegion:動畫:]。

該地區應適當放大你正在展示的東西。

+0

謝謝。這工作。 – user1104325