百度地图相关

iOS 百度地图使用详解

2017-06-29  本文已影响197人  奔跑的小蚂蚁_8b28

最近仿照美团做了款应用,刚好用到百度地图,高德地图之前用的比较多,只是这个项目的后台服务器是另外一个公司做的,他们用的就是百度地图,现在网上用百度地图的还不算太多,博文也是断断续续的,主要是中间跳跃有点大,没有可运行的demo,看不到效果。纠结了好久,结合别人的总结和从百度官网上下载的demo,详细记录一下百度地图的使用过程,分享一下,也便于以后查阅使用。
  百度地图的使用和苹果一样,相对于高德地图来说规范了好多。直接将程序的bundle Identity和appkey值绑定,虽然刚开始用感觉有点不习惯,相信规范严谨对于国内的程序开发也算是一种引导吧。闲言少絮,下面开始百度地图的使用说明。

第一步:注册百度账号,申请appkey。直接上图片效果比较直接。 ,这里面有个小插曲,当初习惯性地将禁用服务ios地图sdk勾选上,做了无数次的测试一直不显示地图页面。纠结了好久,偶然间想到可能是appkey的问题,重新走了一遍,原来把禁用服务勾选上了,改过来就好了,做我们这行的严谨、认真还是很有必要地。
第二步:将百度地图sdk包添加到程序,在AppDelegate导入

import<CoreLocation/CoreLocation.h>

import "AGViewDelegate.h"

import "BMapKit.h"

上述文件,添加如下委托和对象
@interface AppDelegate : UIResponder <UIApplicationDelegate,CLLocationManagerDelegate,BMKGeneralDelegate>
{
AGViewDelegate _viewDelegate;//
BMKMapManager
_mapManager;//百度地图管理器
}
并在

import "BMapKit.h"

添加
BMKMapViewDelegate,BMKLocationServiceDelegate委托对象
@property(nonatomic,retain)BMKMapView* baiduMapView;//地图视图
@property(nonatomic,retain)BMKLocationService* locationService;//百度地图定位服务对象
@synthesize baiduMapView;
@synthesize locationService;
当然不用的时候需要释放掉
if (baiduMapView)
{
[baiduMapView release];
baiduMapView = nil;
}
if (locationService)
{
[locationService release];
locationService = nil;
}

接下来就是地图视图控件使用了
self.baiduMapView = [[[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]autorelease];

//初始化百度地图对象
baiduMapView.delegate = self;
[baiduMapView setMapType:BMKMapTypeStandard];
baiduMapView.zoomLevel=17;//地图级别

//显示定位的蓝点儿必须先开启定位服务
[locationService startUserLocationService];

[baiduMapView setShowsUserLocation:NO];
baiduMapView.userTrackingMode=BMKUserTrackingModeNone;//地图模式
[baiduMapView setShowsUserLocation:YES];//显示定位的蓝点儿

coordinate.latitude = [XtomFunction xfuncGetAppdelegate].currentLocation.coordinate.latitude;//纬度
coordinate.longitude = [XtomFunction xfuncGetAppdelegate].currentLocation.coordinate.longitude;//经度


BMKCoordinateRegion viewRegion = BMKCoordinateRegionMake(coordinate, BMKCoordinateSpanMake(0.3,0.3));
BMKCoordinateRegion adjustedRegion = [baiduMapView regionThatFits:viewRegion];
[baiduMapView setRegion:adjustedRegion animated:YES];

到这里已经可以展示地图信息数据了,当然一些复杂的东西需要下面的委托实现
第四步:百度地图中常用委托方法的使用
/**
*用户方向更新后,会调用此函数
*@param userLocation 新的用户位置
*/

}

//原理类似 UITableView 循环委托加载 CellforRowWithIndexPath

结合
//原理类似 UITableView 循环委托加载 CellforRowWithIndexPath

}也一并分享一下吧。
第五步:百度地图中公交线路信息的获取和公交路线的绘制
公交、地铁、汽车、步行这几个是常见的东西这个比较麻烦一些,感兴趣的可以去百度地图的demo中查询,我给出链接吧。http://download.csdn.net/detail/kuuailetianzi/7907889 至此,百度地图的使用介绍的差不多了,我也该休息休息了。

上一篇 下一篇

猜你喜欢

热点阅读