同一个应用中的多个地图视图

时间:2012-02-01 16:08:50

标签: iphone mkmapview

我写了这段代码,在我的应用的单个页面中添加了一个地图视图。

我想再添加一个不同地图视图的页面 我怎么能这样做?

或者Controller.h

 # import   < UIKit/UIKit.h > 
 # import  < MapKit/MapKit.h >

@interface __3_ProductionsViewController : UIViewController       
{
    MKMapView *mapview;
}

@property (nonatomic, retain) IBOutlet MKMapView *mapview;

-(IBAction)setMap:(id)sender;
-(IBAction)getlocation;  

@end

Controller.m或者

 # import  "__3_ProductionsViewController.h"     
 # import  " NewClass.h "
 # import " Class2.h "

 @implementation __3_ProductionsViewController

 @synthesize mapview;

-(IBAction)getlocation
{   
    mapview.showsUserLocation = YES;
}

-(IBAction)setMap:(id)sender 
{
    switch (((UISegmentedControl *) sender).selectedSegmentIndex)
    {
        case 0:
            mapview.mapType = MKMapTypeSatellite;
            break;

        case 1:
            mapview.mapType = MKMapTypeStandard;
            break;

        case 2:
            mapview.mapType = MKMapTypeHybrid;
            break;

        default:
            break;
    }
}

-(void)viewDidLoad 
{    
    [super viewDidLoad];

    [mapview setMapType:MKMapTypeSatellite];
    [mapview setZoomEnabled:YES];
    [mapview setScrollEnabled:YES];

    MKCoordinateRegion region = { {0.0, 0.0 }, {0.0, 0.0 } };
    region.center.latitude = 45.043615;
    region.center.longitude = 12.149377;
    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;

    [mapview setRegion:region animated:YES];

    NewClass *ann = [[NewClass alloc] init];
    ann.title = @"ADRIA";
    ann.subtitle = @"Adria International Raceway";
    ann.coordinate = region.center;

    [mapview addAnnotation:ann];
}

newclass.h

 # import < Foundation/Foundation.h >
 # import < MapKit/MKAnnotation.h >

 @interface NewClass : NSObject 
 {   
    CLLocationCoordinate2D coordinate;
    NSString *title;
    NSString *subtitle; 
 }

 @property (nonatomic, assign) CLLocationCoordinate2D coordinate;
 @property (nonatomic, copy) NSString *title;
 @property (nonatomic, copy) NSString *subtitle; 

@end

newclass.m

 # import "NewClass.h"

 @implementation NewClass
 @synthesize coordinate,title,subtitle;

@end

0 个答案:

没有答案