在地图视图中突出显示注释

时间:2012-01-26 13:33:43

标签: objective-c ios mkmapview uisplitviewcontroller

对于iPad应用程序,我在左侧有一个带有TableView的SplitView,显示了一个餐馆列表。右侧有一个MapView显示那些餐馆的注释。

我正在尝试缩放到Annotation,并在用户点击左侧表格中的相关餐厅时以某种方式突出显示它。

不幸的是我没有让地图重新加载。

有任何建议或想法如何解决这个问题?

这是我的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 个答案:

答案 0 :(得分:1)

MKMapView为此提供了简单的API:

根据您的用户选择,您可以拨打以下内容:

[mapView setRegion:animated:];

该区域应适当放大您正在展示的东西。

相关问题