允许用户更改地图类型

时间:2013-04-28 18:09:34

标签: ios objective-c

我希望用户能够通过像Apple地图或地图上的按钮一样卷曲右上角来更改地图上的地图类型。有什么想法吗?

- (void)setUpMap {
//setMap

MKMapView *mapView = [[MKMapView alloc] initWithFrame:CGRectMake(10, 14, (self.bounds.size.width - (10 * 2)), (self.bounds.size.height - (10 * 2)))];

mapView.layer.borderColor = kITBarTint.CGColor;
mapView.layer.borderWidth = 1.0;
mapView.layer.cornerRadius = 15.0;
mapView.layer.shadowColor = [UIColor blackColor].CGColor;
mapView.layer.shadowOffset = CGSizeMake(5, 5);
mapView.layer.shadowRadius = 10;
mapView.mapType = MKMapTypeHybrid;

[mapView setDelegate:self];
[mapView setShowsUserLocation:NO];

[self addSubview:mapView];


NSMutableArray *locations = [NSMutableArray array];
BOOL isFirst = YES;
for (ITLocation *location in self.spider.locations) {
    ITObjectMark *mark = [[ITObjectMark alloc] initWithCoordinate:[location geopoint] addressDictionary:nil];
    mark.Object = self.Object;
    [locations addObject:mark];
    if (isFirst) {

        int zoomLevel = 2;

        // use the zoom level to compute the region
        [mapView setCenterCoordinate:[location geopoint] zoomLevel:zoomLevel animated:YES];
        isFirst = NO;
    }
}

[mapView addAnnotations:locations];

}

1 个答案:

答案 0 :(得分:5)

您可以使用UISegmentedControler并设置地图类型。但是对于冰壶,您需要一个新的视图控制器,您可以在其中放置按钮并使用presentmodalviewcontroller样式模态转换部分卷曲...

- (IBAction)setMap:(id)sender {

    switch (((UISegmentedControl *)sender).selectedSegmentIndex) {

        case 0:
        {
            mapView.mapType = MKMapTypeStandard;
            break;
        }

        case 1:
        {
            mapView.mapType = MKMapTypeSatellite;
            break;
        }

        case 2:
        {
            mapView.mapType = MKMapTypeHybrid;
            break;
        }
    }
}

但是对于冰壶,您需要一个新的视图控制器,您可以在其中放置按钮并使用presentmodalviewcontroller样式模态过渡部分卷曲... //示例

- (IBAction)goToSecond:(id)sender
 { 
    InfoController *ainfoController = [[InfoController alloc] 
                                       initWithNibName:@"InfoController" bundle:nil];
    ainfoController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
    [self presentModalViewController:ainfoController animated:YES];
 }

要获取更改,请使用委托...... Delegate example