描述:最近项目中用到了百度地图获取附近的店铺信息,改店铺信息需要用自定义PaoPaoView来展示,其设置步骤如下:

#import <MapKit/MapKit.h>

@interface MapViewController : BaseViewController<BMKMapViewDelegate,BMKLocationServiceDelegate>

BMKMapView          *_mapView;

BMKLocationService  *_locService;

BMKPointAnnotation  *_annotation;

CLLocationCoordinate2D coordinate;                  //设定经纬度

BMKPinAnnotationView *newAnnotation;

- (void)viewWillAppear:(BOOL)animated
{[super viewWillAppear:YES];self.navigationController.navigationBarHidden = NO;_mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放_locService.delegate = self;
}#pragma mark -- UI
- (void)createBaiDuMapView
{_mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];[self.view addSubview:_mapView];_mapView.delegate=self;//用户位置追踪(用户位置追踪用于标记用户当前位置,此时会调用定位服务)_mapView.userTrackingMode=MKUserTrackingModeFollow;//设置地图类型_mapView.mapType=MKMapTypeStandard;_mapView.showsUserLocation = YES;                //设置为可以显示用户位置//设定经纬度SharedInfo *shared = [SharedInfo sharedDataInfo];float latitude = [shared.localLatitude floatValue];float longitude = [shared.localLongitude floatValue];coordinate.latitude = latitude;//纬度coordinate.longitude = longitude;//经度_locService = [[BMKLocationService alloc]init];_locService.delegate=self;[_locService startUserLocationService];_mapView.userTrackingMode=BMKUserTrackingModeNone;//地图模式[_mapView setShowsUserLocation:YES];//显示定位的蓝点儿//设置定位精确度,默认:kCLLocationAccuracyBest[BMKLocationService setLocationDesiredAccuracy:kCLLocationAccuracyBest];//指定最小距离更新(米),默认:kCLDistanceFilterNone[BMKLocationService setLocationDistanceFilter:300.0f];BMKCoordinateRegion viewRegion = BMKCoordinateRegionMake(coordinate, BMKCoordinateSpanMake(0.3,0.3));BMKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];[_mapView setRegion:adjustedRegion animated:YES];}#pragma mark -- HTTP
- (void)shopsList:(NSString *)lng setLat:(NSString *)lat
{NSDictionary  *params = [NSDictionary dictionaryWithObjectsAndKeys:lng,@"lng",lat,@"lat",@"",@"cate_id",@"",@"r_id",@"5000",@"fujin",@"",@"keyword",@"1",@"page",@"20",@"per_page",@"",@"order",@"",@"sort", nil];//[self initMBProgress:@"数据加载中..."];[CKHttpCommunicate createRequest:HTTP_METHOD_NEARBY_STORE_LIST WithParam:params withMethod:@"POST" success:^(id result) {if (result && [[result objectForKey:@"error"]intValue] == 0  ) {NSDictionary *jsonArray = [result objectForKey:@"data"];self.cityData = [jsonArray objectForKey:@"stores"];for (int i = 0; i < self.cityData.count; i ++) {NSDictionary *dic = [self.cityData objectAtIndex:i];NSString *latStr = [dic objectForKey:@"lat"];NSString *lngStr = [dic objectForKey:@"lng"];CLLocationCoordinate2D coor;coor.longitude = [lngStr floatValue];coor.latitude = [latStr floatValue];// 在地图中添加一个PointAnnotation,用于添加大头针_annotation = [[BMKPointAnnotation alloc]init];_annotation.coordinate = coor;//_annotation.title = @"标题";//_annotation.subtitle = @"详情介绍";[_mapView addAnnotation:_annotation]; //添加大头针对象}[_mapView setZoomLevel:15.3f];}} failure:^(NSError *erro) {}];
}#pragma mark -- BaiDuMapDelegate
- (void)mapViewDidFinishLoading:(BMKMapView *)mapView
{//NSLog(@"开始定位");
}//大头针
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{NSString *AnnotationViewID = [NSString stringWithFormat:@"renameMark%d",identity];newAnnotation = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];NSDictionary *dic = [self.cityData objectAtIndex:identity];NSString *store_name = [dic objectForKey:@"store_name"];NSString *store_logo = [dic objectForKey:@"store_logo"];NSString *address    = [dic objectForKey:@"address"];NSString *jianju     = [dic objectForKey:@"jianju"];// 设置颜色((BMKPinAnnotationView*)newAnnotation).pinColor = BMKPinAnnotationColorRed;// 从天上掉下效果((BMKPinAnnotationView*)newAnnotation).animatesDrop = YES;// 设置可拖拽((BMKPinAnnotationView*)newAnnotation).draggable = YES;//设置大头针图标//((BMKPinAnnotationView*)newAnnotation).image = [UIImage imageNamed:@"default_avatar"];popView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 260, 124)];//设置弹出气泡图片UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"map_search_store"]];image.frame = CGRectMake(0, 0, 260, 124);[popView addSubview:image];//泡泡上得图片UIImageView *storeImage  = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 45, 45)];[storeImage sd_setImageWithURL:[NSURL URLWithString:store_logo]placeholderImage:[UIImage imageNamed:@"default_avatar"]];[popView addSubview:storeImage];storeName = [[UILabel alloc]initWithFrame:CGRectMake(71.5, 18, 160, 20)];storeName.text = store_name;storeName.backgroundColor = [UIColor clearColor];storeName.font = [UIFont systemFontOfSize:15];storeName.textColor = [UIColor redColor];[popView addSubview:storeName];//距离spacingLabel = [[UILabel alloc]initWithFrame:CGRectMake(85, 38, 100, 20)];spacingLabel.text = [jianju stringByReplacingOccurrencesOfString:@"千米" withString:@"km"];spacingLabel.backgroundColor = [UIColor clearColor];spacingLabel.font = [UIFont systemFontOfSize:12];spacingLabel.textColor = [UIColor grayColor];[popView addSubview:spacingLabel];//地址addLabel = [[UILabel alloc]initWithFrame:CGRectMake(126, 39, 125, 20)];addLabel.text = address;addLabel.backgroundColor = [UIColor clearColor];addLabel.font = [UIFont systemFontOfSize:12];addLabel.textColor = [UIColor grayColor];[popView addSubview:addLabel];lookBtn = [UIButton buttonWithType:UIButtonTypeCustom];lookBtn.frame = CGRectMake(30, 77, 84, 30);[lookBtn setImage:[UIImage imageNamed:@"go_look_btn"] forState:UIControlStateNormal];[lookBtn addTarget:self action:@selector(lookAction:) forControlEvents:UIControlEventTouchUpInside];lookBtn.tag = identity;[popView addSubview:lookBtn];goBtn = [UIButton buttonWithType:UIButtonTypeCustom];goBtn.frame = CGRectMake(60+84, 77, 84, 30);[goBtn setImage:[UIImage imageNamed:@"go_here_btn"] forState:UIControlStateNormal];[goBtn addTarget:self action:@selector(goAction) forControlEvents:UIControlEventTouchUpInside];[popView addSubview:goBtn];BMKActionPaopaoView *pView = [[BMKActionPaopaoView alloc]initWithCustomView:popView];pView.frame = CGRectMake(0, 0, 260, 124);((BMKPinAnnotationView*)newAnnotation).paopaoView = nil;((BMKPinAnnotationView*)newAnnotation).paopaoView = pView;identity ++;return newAnnotation;
}//选中大头针的时候,返还一个View
- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view
{//NSLog(@"选中大头针");
}//取消选中大头针的时候
- (void)mapView:(BMKMapView *)mapView didDeselectAnnotationView:(BMKAnnotationView *)view
{//NSLog(@"取消选中大头针");
}

百度地图自定义泡泡视图相关推荐

  1. 百度地图 自定义结果面板+分页+图层标注(标注点+搜索)

    百度地图 自定义结果面板+分页+图层标注(标注点+搜索) 示例一: <html> <head><meta http-equiv="Content-Type&qu ...

  2. 百度地图自定义覆盖物,在手机上无法监听click事件

    百度地图自定义覆盖物,在手机上无法监听click事件 最近在做手机web端集成百度地图遇到了个坑儿:手机端不支持自定义覆盖物的click事件: 1.自带的marker是支持的(marker不属于自定义 ...

  3. 百度地图自定义标点。

    百度地图自定义标点. 多个标点方法 可以进行for循环 进行动态标点. <!DOCTYPE html> <html> <head><meta http-equ ...

  4. 百度地图自定义吹出框

    2019独角兽企业重金招聘Python工程师标准>>> 百度地图自定义吹出框 直入正题吧! 这些都是知道的了,看文档添加就行了! 实现三个代理方法: 这个方法类似tableview添 ...

  5. 百度地图自定义信息窗口样式

    在项目中,UI经常会把信息窗口做自定义设计,那么如何实现自定义样式的信息窗口呢.核心代码如下: /** 创建信息窗口* */function _createMapvInfoWindow(width,h ...

  6. 百度地图自定义图标icon 添加本地图片无法显示问题解决

    百度地图自定义图标icon 添加本地图片无法显示问题解决 我们在阿里巴巴矢量库找的icon 保存到本地 结论 我们在阿里巴巴矢量库找的icon 保存到本地 链接: 阿里巴巴矢量库. 图片: 随便找一个 ...

  7. 百度地图自定义标注点

    百度地图自定义标注点 //创建点 var point = new BMap.Point(109.49926175379778, 36.60449676862417); //创建自定义标 //参数1:自 ...

  8. 百度地图瓦片 android,百度地图自定义瓦片图获取

    nodejs代码 const request = require('request'); const fs = require('fs'); const bagpipe = require('bagp ...

  9. 百度地图自定义本地图标无法显示

    目录 1.问题 2.代码 解决方式 参考博文 1.问题 百度地图自定义图标,用本地的图标发现无法显示,百度搜索后又说用require变成模块的,使用之后出现新的问题,Uncaught Referenc ...

最新文章

  1. Linux性能监控和调试
  2. 哈佛大学推荐的20个快乐习惯
  3. koa --- 使用Sequelize连接mysql
  4. 通信之道从微积分到5gpdf_保送清华成博士,华为12年搞通信,他为何如此看待 5G ?| 人物志...
  5. 满汉全席(洛谷-P4171)
  6. 怎么汉语_3分钟,让您明白孩子的汉语应该怎么学!(13年级家长必看)
  7. Swift 弱引用与无主引用
  8. aact portable怎么用_“充电宝”用英语怎么说?可别说成“phone charger”!
  9. 【CyberSecurityLearning 66】提权
  10. 这个开源的去马赛克神器 修复受损漫画无压力
  11. 2021半年度博客总结
  12. 计算机系女学霸男生追,杨紫李现解锁恋爱新姿势:吃最甜的糖,追最燃的梦
  13. 华硕 ROG STRIX Z690-A GAMING WIFI D4 i7-13700K 黑苹果efi引导文件
  14. 微星电脑不能u盘引导linux,微星电脑设置从U盘启动的三种方式
  15. RMAN CROSSCHECK命令 说明
  16. void在java中是什么意思_java中void什么意思
  17. 运放单电源供电和双电源供电
  18. python物性库能调用哪些物质_用于水和水蒸汽物性计算的Python模块——iapws
  19. 基于pycharm的简单爬虫
  20. NMAKE简要教程1:环境配置

热门文章

  1. centos系统一键安装docker环境
  2. AndroidStudio汉化
  3. ardupilot更新油门组合值
  4. This Android SDK requires Android Developer Toolkit version 23.0.0 or above.
  5. python<一>基础
  6. 计算机网络防雷器,网络防雷器 - 宇泰(UTEK) - 全球领先智能通讯解决方案提供商!...
  7. 小米M1刷机包 乐蛙ROM第122期 技术顺畅开发版
  8. 因提供18禁动漫,毒害未成年人,国内最大动漫网站被重罚
  9. python 自动化运维 读取交换机数据_技术干货|数据中心自动化运维技术探索之交换机零配置上线...
  10. 关于新闻资讯的排序问题的一些思路