百度地图demo中的一点代码的优化

 1 @implementation RootViewController
 2
 3 - (void)viewDidLoad
 4 {
 5     [super viewDidLoad];
 6     _demoNameArray = [[NSArray alloc]initWithObjects:
 7                       @"基本地图功能-MapViewBaseDemo",
 8                       @"多地图使用功能-MultiMapViewDemo",
 9                       @"图层展示功能-MapViewDemo",
10                       @"地图操作功能-MapViewControlDemo",
11                       @"UI控制功能-MapViewUISettingDemo",
12                       @"定位功能-LocationDemo",
13                       @"覆盖物功能-AnnotationDemo",
14                       @"自定义绘制-CustomOverlayDemo",
15                       @"POI搜索功能-PoiSearchDemo",
16                       @"地理编码功能-GeocodeDemo",
17                       @"路径规划功能-RouteSearchDemo",
18                       @"公交线路查询-BusLineSearch",
19                       @"离线地图功能-OfflineDemo",
20                       @"短串分享功能-ShortUrlShareDemo",
21                       @"云检索功能-CloudSearchDemo",
22                       @"调启百度导航功能-NavigationDemo",
23                       nil];
24
25     NSMutableArray *array = [[NSMutableArray alloc] init];
26     MapViewBaseDemoViewController *mapViewBaseDemoViewController = [[[MapViewBaseDemoViewController alloc] init] autorelease];
27     mapViewBaseDemoViewController.title = @"基本地图功能";
28     MultiMapViewDemo *multiMapViewDemo = [[[MultiMapViewDemo alloc] init] autorelease];
29     multiMapViewDemo.title = @"多地图使用功能";
30     MapViewDemoViewController *mapviewDemoController = [[[MapViewDemoViewController alloc] init] autorelease];
31     mapviewDemoController.title = @"图层展示功能";
32     MapViewControlDemoViewController *mapviewControlDemoController = [[[MapViewControlDemoViewController alloc] init] autorelease];
33     mapviewControlDemoController.title = @"地图操作功能";
34
35     MapViewUISettingDemoViewController *mapViewUISettingDemoViewController = [[[MapViewUISettingDemoViewController alloc] init] autorelease];
36     mapViewUISettingDemoViewController.title = @"UI控制功能";
37
38     LocationDemoViewController *locationDemoController = [[[LocationDemoViewController alloc] init] autorelease];
39     locationDemoController.title = @"定位功能";
40
41     AnnotationDemoViewController *annotationDemoController = [[[AnnotationDemoViewController alloc] init] autorelease];
42     annotationDemoController.title = @"覆盖物功能";
43
44     CustomOverlayDemoViewController *customOverlayDemo = [[[CustomOverlayDemoViewController alloc] init] autorelease];
45     customOverlayDemo.title = @"自定义绘制";
46
47     PoiSearchDemoViewController *poiSearchDemoController = [[[PoiSearchDemoViewController alloc] init] autorelease];
48     poiSearchDemoController.title = @"POI搜索功能";
49
50     GeocodeDemoViewController *geocodeDemoController = [[[GeocodeDemoViewController alloc] init] autorelease];
51     geocodeDemoController.title = @"地理编码功能";
52
53     RouteSearchDemoViewController *routeSearchDemoController = [[[RouteSearchDemoViewController alloc] init] autorelease];
54     routeSearchDemoController.title = @"路径规划功能";
55
56     BusLineSearchViewController *buslineDemoViewController = [[[BusLineSearchViewController alloc] init] autorelease];
57     buslineDemoViewController.title = @"公交线路查询";
58
59     OfflineDemoViewController *offlineDemoViewController = [[[OfflineDemoViewController alloc] init] autorelease];
60     offlineDemoViewController.title = @"离线地图功能";
61
62     ShortUrlShareDemoViewController *shortUrlShareDemoViewController = [[[ShortUrlShareDemoViewController alloc] init] autorelease];
63     shortUrlShareDemoViewController.title = @"短串分享功能";
64
65     CloudSearchDemoViewController *cloudSearchDemoViewController = [[[CloudSearchDemoViewController alloc] init] autorelease];
66     cloudSearchDemoViewController.title = @"云检索功能";
67
68     NavigationDemoViewController *navigationDemoViewController = [[[NavigationDemoViewController alloc] init] autorelease];
69     navigationDemoViewController.title = @"调启百度导航功能";
70
71     [array addObject:mapViewBaseDemoViewController];
72     [array addObject:multiMapViewDemo];
73     [array addObject:mapviewDemoController];
74     [array addObject:mapviewControlDemoController];
75     [array addObject:mapViewUISettingDemoViewController];
76     [array addObject:locationDemoController];
77     [array addObject:annotationDemoController];
78     [array addObject:customOverlayDemo];
79     [array addObject:poiSearchDemoController];
80     [array addObject:geocodeDemoController];
81     [array addObject:routeSearchDemoController];
82     [array addObject:buslineDemoViewController];
83     [array addObject:offlineDemoViewController];
84     [array addObject:shortUrlShareDemoViewController];
85     [array addObject:cloudSearchDemoViewController];
86     [array addObject:navigationDemoViewController];
87
88     _viewControllerArray = array;

      }

#pragma mark -

#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

UIViewController* viewController = [_viewControllerArray objectAtIndex:indexPath.section];

UIBarButtonItem *customLeftBarButtonItem = [[UIBarButtonItem alloc] init];

customLeftBarButtonItem.title = @"返回";

self.navigationItem.backBarButtonItem = customLeftBarButtonItem;

[customLeftBarButtonItem release];

[self.navigationController pushViewController:viewController animated:YES];

}

 

以上是百度地图中demo的一点代码,是实现的功能是在一个tableview中点击不同的cell,就会转跳到不同的控制器,一显示百度地图不同的功能!如下图所示:

觉得这段代码有点冗余,所以就想优化一下,下面是自己的优化后的代码!

 1 - (void)viewDidLoad
 2 {
 3     [super viewDidLoad];
 4     _demoNameArray = [[NSArray alloc]initWithObjects:
 5                       @"基本地图功能-MapViewBaseDemo",
 6                       @"多地图使用功能-MultiMapViewDemo",
 7                       @"图层展示功能-MapViewDemo",
 8                       @"地图操作功能-MapViewControlDemo",
 9                       @"UI控制功能-MapViewUISettingDemo",
10                       @"定位功能-LocationDemo",
11                       @"覆盖物功能-AnnotationDemo",
12                       @"自定义绘制-CustomOverlayDemo",
13                       @"POI搜索功能-PoiSearchDemo",
14                       @"地理编码功能-GeocodeDemo",
15                       @"路径规划功能-RouteSearchDemo",
16                       @"公交线路查询-BusLineSearch",
17                       @"离线地图功能-OfflineDemo",
18                       @"短串分享功能-ShortUrlShareDemo",
19                       @"云检索功能-CloudSearchDemo",
20                       @"调启百度导航功能-NavigationDemo",
21                       nil];
22
23
24       [self setupViewController:[MapViewBaseDemoViewController class] title:@"基本地图功能"];
25     [self setupViewController:[MultiMapViewDemo class] title:@"多地图使用功能"];
26     [self setupViewController:[MapViewDemoViewController class] title:@"图层展示功能"];
27     [self setupViewController:[MapViewControlDemoViewController class] title:@"地图操作功能"];
28     [self setupViewController:[MapViewUISettingDemoViewController class] title:@"UI控制功能"];
29     [self setupViewController:[LocationDemoViewController class] title:@"定位功能"];
30     [self setupViewController:[AnnotationDemoViewController class] title:@"覆盖物功能"];
31     [self setupViewController:[CustomOverlayDemoViewController class] title:@"自定义绘制"];
32     [self setupViewController:[PoiSearchDemoViewController class] title:@"POI搜索功能"];
33     [self setupViewController:[GeocodeDemoViewController class] title:@"地理编码功能"];
34     [self setupViewController:[RouteSearchDemoViewController class] title:@"路径规划功能"];
35     [self setupViewController:[BusLineSearchViewController class] title:@"公交线路查询"];
36     [self setupViewController:[OfflineDemoViewController class] title:@"离线地图功能"];
37     [self setupViewController:[ShortUrlShareDemoViewController class] title:@"短串分享功能"];
38     [self setupViewController:[CloudSearchDemoViewController class] title:@"云检索功能"];
39     [self setupViewController:[NavigationDemoViewController class] title:@"调启百度导航功能"];
40 }
41
42
43 - (void)setupViewController:(Class)controller  title:(NSString *)title
44 {
45
46     UIViewController *viewController = [[[controller alloc] init] autorelease];
47
48     viewController.title = title;
49
50     [self.viewControllerArray addObject:viewController];
51
52 }
53
54 #pragma mark -
55 #pragma mark Table view delegate
56
57 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
58     UIViewController* viewController = [self.viewControllerArray objectAtIndex:indexPath.section];
59     UIBarButtonItem *customLeftBarButtonItem = [[UIBarButtonItem alloc] init];
60     customLeftBarButtonItem.title = @"返回";
61     self.navigationItem.backBarButtonItem = customLeftBarButtonItem;
62     [customLeftBarButtonItem release];
63     [self.navigationController pushViewController:viewController animated:YES];
64
65 }
时间: 2024-10-13 15:37:54

百度地图demo中的一点代码的优化的相关文章

Android studio百度地图demo出现230错误,key校验失败

转自daoxiaomianzi原文 Android studio 百度地图demo出现230错误,key校验失败 使用AndroidStudio导入Baidu地图的as版的demo,引入后,发现没有key,于是到http://lbsyun.baidu.com/apiconsole/key,创建应用,申请key,但是把sha1和报名都输入后,将key复制到manifest.xml里,部署到手机上,提示: 验证出错,错误码:230,请AndroidManifest.xml文件中检查 kye 设置.

百度地图demo

按不同策略的驾车导航 百度地图demo,布布扣,bubuko.com

android 百度地图Demo

原文:android 百度地图Demo 源代码下载地址:http://www.zuidaima.com/share/1550463561714688.htm 通过调用百度的api来进行定位和导航的一个android客户端 java源代码截图:

简单高效快捷的百度地图demo

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   <html xmlns="http://www.w3.org/1999/xhtml">   <head>   <meta charset="utf

百度地图 - demo

项目需要集成百度地图,那么关于如何集成百度地图的事,就自己去百度开放平台查看文档吧,这是非常简单的事,在这里就不多说了. 那么下面我就说说我在这个demo里所做的事. 首先,项目需要具备定位及计算两地的距离 其次,项目需要根据两个地点来拿到所有路线,并且可根据不同的策略拿到对应的最佳路线. 最后,需要拿到打车相关信息 那么这里我就自己写了一个单例类,这是在内部处理所有的代理,外部可以非常方便地调用,如果有好的建议,请在评论中赐教,谢谢! [objc] view plaincopy // //  

【Android接百度地图API】百度地图Demo点击按钮闪退

运行百度地图自带的BaiduMap_AndroidSDK_v4.1.0_Sample里面的BaiduMapsApiASDemo发现点击上面的按钮会闪退,控制台报的是xml的问题 查了一下,官方文档特别交代了要加入SDKInitializer.initialize(getApplicationContext()); 但是Demo里面没有,因而要加上. 即可解决Demo的Bug.

从百度地图API中抠出来的一个js方法,计算百度地图坐标距离

从百度地图api(http://developer.baidu.com/map/jsdemo.htm#a6_1)中抠出来的一个js方法,计算百度地图坐标距离 可读行还没还原,能用就行~ function fD(a, b, c) { for (; a > c;) a -= c - b; for (; a < b;) a += c - b; return a; }; function jD(a, b, c) { b != null && (a = Math.max(a, b));

百度地图自己添加 标识地点 代码

<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type

Jquery Mobile 百度地图 Demo

首先非常感谢franck分享的Demo! Demo截图: 下面是franck对此Demo的说明: 原理:1.通过百度拾取坐标系统获得点位的坐标. http://api.map.baidu.com/lbsapi/getpoint/index.html 2.在网页的<head>中插入百度API引用脚本. <script type="text/javascript" src="http://api.map.baidu.com/api?key=&v=1.1&