你的位置:首页 > 操作系统

[操作系统]UITableViewController和XML解析还有地图的简单结合


 

 

然后我的代码就按照上面的这个顺序输出。

 

#import <Foundation/Foundation.h>#import <MapKit/MapKit.h>@interface MapAnnotation : NSObject<MKAnnotation>@property(nonatomic,readwrite) CLLocationCoordinate2D coordinate;@property(nonatomic,strong) NSString* titler;-(id)initWithTirle:(NSString *)titler andCoordinate:(CLLocationCoordinate2D)coordinate2d;@end

 

 

 

#import "MapAnnotation.h"@implementation MapAnnotation-(id)initWithTirle:(NSString *)titler andCoordinate:(CLLocationCoordinate2D)coordinate2d{  self.titler=titler;  self.coordinate=coordinate2d;  return self;}@end

 

 

 

#import <UIKit/UIKit.h>#import "RootTableViewController.h"@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@end

 

 

#import "AppDelegate.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  self.window.rootViewController=[[UINavigationController alloc] initWithRootViewController:[[RootTableViewController alloc]initWithStyle:UITableViewStylePlain]];  return YES;}

 

 

 

#import <UIKit/UIKit.h>#import <MapKit/MapKit.h>#import <CoreLocation/CoreLocation.h>@interface ViewController : UIViewController<MKMapViewDelegate>@property(strong,nonatomic)NSString *latitude;@property(strong,nonatomic)NSString *longitude;@end

 

 

 

#import "ViewController.h"#import "MapAnnotation.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {  [super viewDidLoad];  //初始化你的地图在手机上的大小  MKMapView *mapView=[[MKMapView alloc] initWithFrame:self.view.frame];  //遵循协议  mapView.delegate = self;  //当前地图以坐标为中心点扩散   mapView.centerCoordinate=CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);  //地图类型  mapView.mapType=MKMapTypeHybrid;  //创建位置  CLLocationCoordinate2D location;  //位置的经度纬度  location.latitude=[self.latitude doubleValue];  location.longitude=[self.longitude doubleValue];  //用大头针来接收你所在的位置  MapAnnotation *newAnnotation=[[MapAnnotation alloc] initWithTirle:@"Apple Head quaters" andCoordinate:location];  //添加到你的地图上  [mapView addAnnotation:newAnnotation];   //把地图添加你的页面上  [self.view addSubview:mapView];  self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"back" style:2 target:self action:@selector(backPage)];  }- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views{    MKAnnotationView *annotationView=[views objectAtIndex:0];  //代理属性  调用方法  id<MKAnnotation>mp=[annotationView annotation];  //缩放你所看到的的X轴和Y轴  MKCoordinateRegion region=MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500);  //mv 是否实现缩放  [mv setRegion:region animated:YES];  //mv 是否实现mp  [mv selectAnnotation:mp animated:YES];  }-(void)backPage{  [self.navigationController popToRootViewControllerAnimated:YES];}- (void)didReceiveMemoryWarning {  [super didReceiveMemoryWarning];  // Dispose of any resources that can be recreated.}@end

 

 

 

#import <UIKit/UIKit.h>#import "ViewController.h"@interface RootTableViewController : UITableViewController<NS

 

 

 

#import "RootTableViewController.h"@interface RootTableViewController ()@end@implementation RootTableViewController- (void)viewDidLoad {  [super viewDidLoad];  self.title=@"城市列表";  NSURL *url=[NSURL URLWithString:@"http://www.meituan.com/api/v1/divisions?mtt=1.help%2Fapi.0.0.im7coqq1"];  NSData *data=[NSData dataWithContentsOfURL:url];  NS