在2月11号写了一些对百度地图SDK如何加入到项目中的一些步骤以及注意的,然后一直没写下面的东西,今天就来补充一下...
① 在之前的配置中,如果你按照我写的步骤完成,那么基本上来说,配置这块问题就不大,这时候如果你看过http://pan.baidu.com/s/1eQCN3ZO这个网址共享的pdf文档里进行代码书写,然后运行,那么你可能会遇到一个很头疼的问题,那就是你的控制台会显示"manager start failed".
ps:我第一次弄这个的时候相当头疼,查了很多资料,逛了很久的百度LBS开会论坛才找到这个网址,共享给大家:http://bbs.lbsyun.baidu.com/forum.php?mod=viewthread&tid=14266&extra=page%3D1,真的是很想吐槽,百度的大牛们,你们写了pdf开发文档,为什么不把这些个东西也写进入呢???培养我们自学能力么?
② 这次我们公司的需求不太好表达,我简而言之就是,要在百度地图中显示多个标记,不多说了,直接上代码给大家,写的不好,大家见谅,我自己也只是想看这个功能是否能实现..呵呵.(因为我一个同事说这个不能搞,事实证明,自己试试最好)
AppDelegate.h
嗯哼,是不是有3个标记了???OK,今天到此为止...
① 在之前的配置中,如果你按照我写的步骤完成,那么基本上来说,配置这块问题就不大,这时候如果你看过http://pan.baidu.com/s/1eQCN3ZO这个网址共享的pdf文档里进行代码书写,然后运行,那么你可能会遇到一个很头疼的问题,那就是你的控制台会显示"manager start failed".
ps:我第一次弄这个的时候相当头疼,查了很多资料,逛了很久的百度LBS开会论坛才找到这个网址,共享给大家:http://bbs.lbsyun.baidu.com/forum.php?mod=viewthread&tid=14266&extra=page%3D1,真的是很想吐槽,百度的大牛们,你们写了pdf开发文档,为什么不把这些个东西也写进入呢???培养我们自学能力么?
② 这次我们公司的需求不太好表达,我简而言之就是,要在百度地图中显示多个标记,不多说了,直接上代码给大家,写的不好,大家见谅,我自己也只是想看这个功能是否能实现..呵呵.(因为我一个同事说这个不能搞,事实证明,自己试试最好)
AppDelegate.h
#importAppDelegate.m#import "BMapKit.h" @class ViewController; @interface AppDelegate : UIResponder { BMKMapManager * _mapManger; } @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) ViewController * viewController; @end
#import "AppDelegate.h" #import "ViewController.h" @interface AppDelegate ()ViewController.h@end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. _mapManger = [[BMKMapManager alloc]init]; BOOL ret = [_mapManger start:@"c0e6RneQT33gwzC0vuQCXCkb" generalDelegate:self]; if (!ret) { NSLog(@"manager start failed!"); } self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; // self.window.rootViewController = [ViewController ]; self.viewController = [[ViewController alloc]init]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; } - (void)onGetNetworkState:(int)iError { if (0 == iError) { NSLog(@"联网成功"); }else { NSLog(@"onGetNetworkState %d",iError); } } - (void)onGetPermissionState:(int)iError { if (0 == iError) { NSLog(@"授权成功"); }else { NSLog(@"onGetPermissionState %d",iError); } }
#importViewController.m#import "BMapKit.h" @interface ViewController : UIViewController { BMKMapView * _mapView; } @end
#import "ViewController.h" #import "MyAnimatedAnnotationView.h" #import "BMKAnnotation.h" #import "BMKPinAnnotationView.h" @interface ViewController () { BMKPointAnnotation* pointAnnotation; BMKPointAnnotation* animatedAnnotation; BMKPinAnnotationView * newAnnotation; } @property (strong, nonatomic) NSArray * latitudeArray; @property (strong, nonatomic) NSArray * longitudeArray; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; [self.view addSubview:_mapView]; //适配ios7 if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)) { // self.edgesForExtendedLayout=UIRectEdgeNone; self.navigationController.navigationBar.translucent = NO; } //设置地图缩放级别 [_mapView setZoomLevel:11]; //添加标注 self.latitudeArray = @[@"39.915",@"39.997",@"39.900"]; self.longitudeArray = @[@"116.404",@"116.268",@"116.392"]; NSMutableArray * arr = [NSMutableArray array]; //分配内存 for (int i = 0; i < self.latitudeArray.count; i ++) { BMKPointAnnotation * a = [self getAnnotation]; [arr addObject:a]; } [_mapView addAnnotations:arr]; } - (BMKPointAnnotation *)getAnnotation { static NSInteger num = 0; BMKPointAnnotation * pointAnnotation1 = [[BMKPointAnnotation alloc]init]; CLLocationCoordinate2D coor; NSString * latitude = self.latitudeArray[num]; NSString * longitude = self.longitudeArray[num]; coor.latitude = latitude.floatValue; coor.longitude = longitude.floatValue; pointAnnotation1.coordinate = coor; pointAnnotation1.title = @"test"; pointAnnotation1.subtitle = @"此Annotation可拖拽1!"; num++; return pointAnnotation1; } - (void)viewWillAppear:(BOOL)animated { [_mapView viewWillAppear]; _mapView.delegate = self; } - (void)viewWillDisappear:(BOOL)animated { [_mapView viewWillDisappear]; _mapView.delegate = nil; } - (void)dealloc { if (_mapView) { _mapView = nil; } } #pragma mark - #pragma mark implement BMKMapViewDelegate - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id这里还会用到百度地图SDK中的一个自定义类,大家自己加进去,MyAnimatedAnnotationView.h和MyAnimatedAnnotationView.m,加好之后,运行,效果如下:)annotation { NSString *AnnotationViewID = @"renameMark"; if (newAnnotation == nil) { newAnnotation = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; // 设置颜色 ((BMKPinAnnotationView*)newAnnotation).pinColor = BMKPinAnnotationColorPurple; // 从天上掉下效果 ((BMKPinAnnotationView*)newAnnotation).animatesDrop = YES; // 设置可拖拽 ((BMKPinAnnotationView*)newAnnotation).draggable = NO; } return newAnnotation; } // 当点击annotation view弹出的泡泡时,调用此接口 - (void)mapView:(BMKMapView *)mapView annotationViewForBubble:(BMKAnnotationView *)view; { NSLog(@"paopaoclick"); }
嗯哼,是不是有3个标记了???OK,今天到此为止...
收藏的用户(0) X
正在加载信息~
推荐阅读
最新回复 (0)
站点信息
- 文章2305
- 用户1336
- 访客11455432
每日一句
Talent without working hard is nothing.
没有努力,天份不代表什么。
没有努力,天份不代表什么。
MySQL 数据库优化
This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de
免ROOT实现模拟点击任意位置
Mobaxterm终端神器
CreateProcessW要注意的细节问题
Autonomous NAT Traversal
【教程】win10 彻底卸载edge浏览器
eclipse工程基于Xposed的一个简单Hook
排名前5的开源在线机器学习
Mac OS最简单及(Karabiner)快捷键设置
发一款C++编写的麻将
VMware NAT端口映射外网访问虚拟机linux
独家发布最新可用My-AutoPost——wordpress 采集器
新会员