<key>LSApplicationQueriesSchemes</key>
<array>
<string>baidumap</string>
</array>
#import "AppDelegate.h"
#import <BaiduMapAPI_Base/BMKMapManager.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//创建并初始化一个引擎对象
BMKMapManager *manager = [[BMKMapManager alloc] init];
//启动地图引擎
BOOL success = [manager start:@"zBWLNgRUrTp9CVb5Ez6gZpNebljmYylO" generalDelegate:nil];
if (!success) {
NSLog(@"失败");
}
// Override point for customization after application launch.
return YES;
}
#import "ViewController.h"
#import <BaiduMapAPI_Map/BMKMapView.h>
@interface ViewController ()<BMKMapViewDelegate>
@property (nonatomic,strong) BMKMapView *mapView;//地图视图
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//初始化地图
self.mapView = [[BMKMapView alloc] initWithFrame:self.view.frame];
self.mapView.delegate =self;
//设置地图的显示样式
self.mapView.mapType = BMKMapTypeSatellite;//卫星地图
//设定地图是否打开路况图层
self.mapView.trafficEnabled = YES;
//底图poi标注
self.mapView.showMapPoi = NO;
//在手机上当前可使用的级别为3-21级
self.mapView.zoomLevel = 21;
//设定地图View能否支持旋转
self.mapView.rotateEnabled = NO;
//设定地图View能否支持用户移动地图
self.mapView.scrollEnabled = NO;
//添加到view上
[self.view addSubview:self.mapView];
//还有很多属性,根据需求查看API
}
#import "ViewController.h"
#import <BaiduMapAPI_Map/BMKMapView.h>
#import <BaiduMapAPI_Location/BMKLocationService.h>
@interface ViewController ()<BMKLocationServiceDelegate,BMKMapViewDelegate>
@property (nonatomic,strong) BMKMapView *mapView;//地图视图
@property (nonatomic,strong) BMKLocationService *service;//定位服务
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//初始化地图
self.mapView = [[BMKMapView alloc] initWithFrame:self.view.frame];
self.mapView.delegate =self;
//添加到view上
[self.view addSubview:self.mapView];
//初始化定位
self.service = [[BMKLocationService alloc] init];
//设置代理
self.service.delegate = self;
//开启定位
[self.service startUserLocationService];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark -------BMKLocationServiceDelegate
/**
*用户位置更新后,会调用此函数
*@param userLocation 新的用户位置
*/
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation {
//展示定位
self.mapView.showsUserLocation = YES;
//更新位置数据
[self.mapView updateLocationData:userLocation];
//获取用户的坐标
self.mapView.centerCoordinate = userLocation.location.coordinate;
self.mapView.zoomLevel =18;
}
#import "ViewController.h"
#import <BaiduMapAPI_Map/BMKMapView.h>
#import <BaiduMapAPI_Location/BMKLocationService.h>
#import <BaiduMapAPI_Search/BMKPoiSearch.h>
#import <BaiduMapAPI_Map/BMKAnnotation.h>
#import <BaiduMapAPI_Map/BMKPointAnnotation.h>
#import <BaiduMapAPI_Map/BMKPinAnnotationView.h>
#define kWidth [UIScreen mainScreen].bounds.size.width
@interface ViewController ()<BMKLocationServiceDelegate,BMKPoiSearchDelegate,BMKMapViewDelegate>
@property (nonatomic,strong) BMKMapView *mapView;//地图视图
@property (nonatomic,strong) BMKLocationService *service;//定位服务
@property (nonatomic,strong) BMKPoiSearch *poiSearch;//搜索服务
@property (nonatomic,strong) NSMutableArray *dataArray;
@end
@implementation ViewController
- (NSMutableArray *)dataArray {
if (!_dataArray) {
_dataArray = [NSMutableArray array];
}
return _dataArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
//初始化地图
self.mapView = [[BMKMapView alloc] initWithFrame:self.view.frame];
self.mapView.delegate =self;
// //设置地图的显示样式
// self.mapView.mapType = BMKMapTypeSatellite;//卫星地图
//
// //设置路况
// self.mapView.trafficEnabled = YES;
//
// //底图poi标注
// self.mapView.showMapPoi = NO;
//
// //在手机上当前可使用的级别为3-21级
// self.mapView.zoomLevel = 21;
//
// //旋转
// self.mapView.rotateEnabled = NO;
//
// //拖拽
// self.mapView.scrollEnabled = NO;
//
[self.view addSubview:self.mapView];
//初始化定位
self.service = [[BMKLocationService alloc] init];
//设置代理
self.service.delegate = self;
//开启定位
[self.service startUserLocationService];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark -------BMKLocationServiceDelegate
/**
*用户位置更新后,会调用此函数
*@param userLocation 新的用户位置
*/
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation {
//展示定位
self.mapView.showsUserLocation = YES;
//更新位置数据
[self.mapView updateLocationData:userLocation];
//获取用户的坐标
self.mapView.centerCoordinate = userLocation.location.coordinate;
self.mapView.zoomLevel =18;
//初始化搜索
self.poiSearch =[[BMKPoiSearch alloc] init];
self.poiSearch.delegate = self;
//初始化一个周边云检索对象
BMKNearbySearchOption *option = [[BMKNearbySearchOption alloc] init];
//索引 默认为0
option.pageIndex = 0;
//页数默认为10
option.pageCapacity = 50;
//搜索半径
option.radius = 200;
//检索的中心点,经纬度
option.location = userLocation.location.coordinate;
//搜索的关键字
option.keyword = @"小吃";
//根据中心点、半径和检索词发起周边检索
BOOL flag = [self.poiSearch poiSearchNearBy:option];
if (flag) {
NSLog(@"搜索成功");
//关闭定位
[self.service stopUserLocationService];
}
else {
NSLog(@"搜索失败");
}
}
#pragma mark -------BMKPoiSearchDelegate
/**
*返回POI搜索结果
*@param searcher 搜索对象
*@param poiResult 搜索结果列表
*@param errorCode 错误号,@see BMKSearchErrorCode
*/
- (void)onGetPoiResult:(BMKPoiSearch *)searcher result:(BMKPoiResult *)poiResult errorCode:(BMKSearchErrorCode)errorCode {
//若搜索成功
if (errorCode ==BMK_SEARCH_NO_ERROR) {
//POI信息类
//poi列表
for (BMKPoiInfo *info in poiResult.poiInfoList) {
[self.dataArray addObject:info];
//初始化一个点的注释 //只有三个属性
BMKPointAnnotation *annotoation = [[BMKPointAnnotation alloc] init];
//坐标
annotoation.coordinate = info.pt;
//title
annotoation.title = info.name;
//子标题
annotoation.subtitle = info.address;
//将标注添加到地图上
[self.mapView addAnnotation:annotoation];
}
}
}
/**
*返回POI详情搜索结果
*@param searcher 搜索对象
*@param poiDetailResult 详情搜索结果
*@param errorCode 错误号,@see BMKSearchErrorCode
*/
- (void)onGetPoiDetailResult:(BMKPoiSearch *)searcher result:(BMKPoiDetailResult *)poiDetailResult errorCode:(BMKSearchErrorCode)errorCode {
NSLog(@"%@",poiDetailResult.name);
}
#pragma mark -------------BMKMapViewDelegate
/**
*根据anntation生成对应的View
*@param mapView 地图View
*@param annotation 指定的标注
*@return 生成的标注View
*/
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation {
//如果是注释点
if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
//根据注释点,创建并初始化注释点视图
BMKPinAnnotationView *newAnnotation = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"an"];
//设置大头针的颜色
newAnnotation.pinColor = BMKPinAnnotationColorRed;
//设置动画
newAnnotation.animatesDrop = YES;
return newAnnotation;
}
return nil;
}
/**
*当选中一个annotation views时,调用此接口
*@param mapView 地图View
*@param views 选中的annotation views
*/
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view {
//poi详情检索信息类
BMKPoiDetailSearchOption *option = [[BMKPoiDetailSearchOption alloc] init];
BMKPoiInfo *info = self.dataArray.firstObject;
//poi的uid,从poi检索返回的BMKPoiResult结构中获取
option.poiUid = info.uid;
/**
*根据poi uid 发起poi详情检索
*异步函数,返回结果在BMKPoiSearchDelegate的onGetPoiDetailResult通知
*@param option poi详情检索参数类(BMKPoiDetailSearchOption)
*@return 成功返回YES,否则返回NO
*/
BOOL flag = [self.poiSearch poiDetailSearch:option];
if (flag) {
NSLog(@"检索成功");
}
else {
NSLog(@"检索失败");
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有