博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
《iPad开发从入门到精通》——6.5节地图信息
阅读量:6639 次
发布时间:2019-06-25

本文共 6057 字,大约阅读时间需要 20 分钟。

本节书摘来自异步社区《iPad开发从入门到精通》一书中的第6章,第6.5节地图信息,作者 杨春泽,更多章节内容可以访问云栖社区“异步社区”公众号查看

6.5 地图信息

iPad开发从入门到精通
通过此功能,可以在地图中查看某条公交线路的信息,这样更具有直观性,大大地方便了用户的浏览。本系统可以分为如下3种显示地图的样式。
Standard。
Statellite。
Hybird。
除此之外,还提供了网页地图功能。

6.5.1 地图主视图

地图主视图CBus_MapView.xib的UI界面效果如图6-11所示。在上方显示3个选项卡,在下方显示了地图信息。

f61f31d3d45ab39a125d7b9ed57f43d4cae1a22a

实现文件 CBus_MapViewController.m的主要代码如下所示。

#import "CBus_MapViewController.h"#import "CBus_WebMapViewController.h"#import "CDataContainer.h"@implementation CBus_MapViewController@synthesize cityMapView,mapStyleSegCtr,mapNavigationBar;@synthesize webMapViewController;- (void)dealloc{  [super dealloc];  [cityMapView release];  [mapStyleSegCtr release];  [mapNavigationBar release];  [webMapViewController release];}- (void)didReceiveMemoryWarning{  // 释放视图  [super didReceiveMemoryWarning];}#pragma mark - View lifecycle- (void)viewDidLoad{  [super viewDidLoad];  UIBarButtonItem *webMapButton = [[UIBarButtonItem alloc]                  initWithTitle:@"WebMap"                  style:UIBarButtonItemStyleBordered                  target:self                  action:@selector(goToWebMap:)];  self.navigationItem.rightBarButtonItem = webMapButton;  [webMapButton release];  CLLocationManager *locationMananger = [[CLLocationManager alloc] init];  locationMananger.delegate = self;  locationMananger.desiredAccuracy = kCLLocationAccuracyBest;  locationMananger.distanceFilter = 1000.0;  [locationMananger startUpdatingHeading];  MKCoordinateSpan theSpan;  theSpan.latitudeDelta = 0.05;  theSpan.longitudeDelta = 0.05;  MKCoordinateRegion theRegion;  theRegion.center = [[locationMananger location]coordinate];  theRegion.span = theSpan;  [cityMapView setRegion:theRegion];  [locationMananger release];}- (IBAction) OnSegmentIndexChanged:(id)sender{  if ([sender selectedSegmentIndex] == 0){    NSLog(@"--------------OnSegmentIndexChanged1-------");    cityMapView.mapType = MKMapTypeStandard;  }  else if([sender selectedSegmentIndex] == 1){    NSLog(@"--------------OnSegmentIndexChanged2-------");    cityMapView.mapType = MKMapTypeSatellite;  }  else if([sender selectedSegmentIndex] == 2){    NSLog(@"--------------OnSegmentIndexChanged3-------");    cityMapView.mapType = MKMapTypeHybrid;  }}- (void)viewWillAppear:(BOOL)animated{  [super viewWillAppear:animated];  NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];  NSInteger styleNum = [userDefault integerForKey:@"styleType"];  switch (styleNum) {    case 0:{      [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;      self.navigationController.navigationBar.barStyle = UIBarStyleDefault;      self.mapStyleSegCtr.tintColor = [UIColor colorWithRed:0.48  green: 0.56 blue:0.66 alpha:1.0];      self.mapNavigationBar.barStyle = UIBarStyleDefault;      break;    }    case 1:{      [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyle BlackOpaque;      self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;      self.mapStyleSegCtr.tintColor = [UIColor darkGrayColor];      self.mapNavigationBar.barStyle = UIBarStyleBlackOpaque;      break;    }  }}- (IBAction)goToWebMap:(id)sender{  CBus_WebMapViewController *theController = [[CBus_WebMapViewController alloc] initWithNibName:@"CBus_WebMapView" bundle:nil];  self.webMapViewController = theController;  [UIView beginAnimations:@"View Flip" context:nil];  [UIView setAnimationDuration:1.0];  [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView: self.navigationController.view cache:NO];  [self.navigationController pushViewController:webMapViewController animated:YES];  [UIView commitAnimations];  [theController release];}- (void)viewDidUnload{  [super viewDidUnload];  }- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{  // Return YES for supported orientations  return (interfaceOrientation == UIInterfaceOrientationPortrait);}@end

执行效果如图6-12所示。

e720424a323a550fba73f6239cf9418661b5b283

6.5.2 Web地图视图

为了便于用户详细浏览公交路线,本项目还提供了Web地图功能,CBus_WebMapView.xibUI界面效果如图6-13所示。

6a53f84c790b5d1f9851256a1ee0495e3f0feafd

实现文件CBus_WebMapViewController.m的主要代码如下所示。

#import "CBus_WebMapViewController.h"@implementation CBus_WebMapViewController@synthesize myWenView;// 视图初始化- (void)viewDidLoad {  [super viewDidLoad];    self.navigationItem.hidesBackButton = YES;  UIBarButtonItem *mapButton = [[UIBarButtonItem alloc]       initWithTitle:@"Map"         style:UIBarButtonItemStyleBordered     target:selfaction:@selector(goToMap:)];    self.navigationItem.rightBarButtonItem = mapButton;    NSMutableString *googleSearch = [NSMutableString stringWithFormat:@"http://ditu. google.cn/maps?f=d&source=s_d&saddr='西安市火车站'&daddr='西安市钟楼'&hl=zh&t=m&dirflg=h"];  [myWenView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[google Search stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]];  [mapButton release];}- (IBAction) goToMap:(id)sender{  [UIView beginAnimations:@"View Flip" context:nil];  [UIView setAnimationDuration:1.0];  [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.  navigationController.view cache:NO];  [self.navigationController popViewControllerAnimated:NO];  [UIView commitAnimations];}- (void)viewWillAppear:(BOOL)animated{  [super viewWillAppear:animated];  NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];  NSInteger styleNum = [userDefault integerForKey:@"styleType"];  switch (styleNum) {    case 0:{      [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;      self.navigationController.navigationBar.barStyle = UIBarStyleDefault;      break;    }    case 1:{      [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyle BlackOpaque;      self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;      break;    }  }}- (void)didReceiveMemoryWarning {  // 释放视图  [super didReceiveMemoryWarning];}- (void)viewDidUnload {  [super viewDidUnload];  self.myWenView=nil;}- (void)dealloc {  [super dealloc];  [self.myWenView release];}@end

执行效果如图6-14所示。

7c212a5dd678fd7d5f84d9efab6362228bcb12e0

转载地址:http://yxpvo.baihongyu.com/

你可能感兴趣的文章
systemctl 配置mysql 开机启动
查看>>
【Oracle】Exadata虚拟机配置(一)
查看>>
线性相关性度量
查看>>
vector容器的实现
查看>>
C#动态调用WCF接口
查看>>
【Hibernate步步为营】--多对多映射具体解释
查看>>
百度地图SDK for Android【Demo兴趣点搜索】
查看>>
动态规划6-最长上升子序列
查看>>
shell 中各种符号的含义
查看>>
Zabbix 3.0 LTS安装配置
查看>>
PHP基础
查看>>
【IPC进程间通讯之三】内存映射文件Mapping File
查看>>
easyui 时间段校验,开始时间小于结束时间,并且时间间隔不能超过30天
查看>>
centos上安装配置java WEB环境_java(转)
查看>>
oracle procedure存储过程
查看>>
logstash进程杀不掉
查看>>
Linux中磁盘分区、格式化、挂载等管理
查看>>
HTML5学习之FileReader接口
查看>>
在QT搭建的播放器外壳中嵌入SDL的窗口
查看>>
让anujs支持rc-select
查看>>