百度地图自定义泡泡视图
来源:互联网 发布:银行家算法实现目的 编辑:程序博客网 时间:2024/05/01 16:21
描述:最近项目中用到了百度地图获取附近的店铺信息,改店铺信息需要用自定义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(@"取消选中大头针");}
0 0
- 百度地图自定义泡泡视图
- iOS中设置百度地图自定义标注图片,自定义泡泡
- 百度地图IOS平台开发--自定义大头钉以及泡泡
- 百度地图不点击自动弹出泡泡(paopao)【自定义】
- Swift 百度地图自定义弹出视图
- Android百度地图实现搜索和定位及自定义图标绘制并点击时弹出泡泡
- Android百度地图实现搜索和定位及自定义图标绘制并点击时弹出泡泡
- IOS-OC-百度地图批量默锚点-点击视图自定义
- 地图展示自定义视图
- 百度地图API自定义地图
- 百度自定义地图控件
- iOS百度地图自定义
- 百度地图自定义Markers
- 百度地图自定义边界
- 百度地图自定义大头针
- 百度地图自定义气泡
- 百度地图自定义气泡
- 百度地图自定义控件
- HDU 5285 wyh2000 and pupil(dfs或种类并查集)
- eclipse修改web项目部署路径
- 修复WCF异常《System.ArgumentException: 已经存在名称为“UriTemplateMatchResults”的属性》
- Linux面试题汇总答案
- unconfined是什么(属性呢)
- 百度地图自定义泡泡视图
- JVM内存分配与回收策略
- error C2248: “CObject::CObject”: 无法访问 private 成员(在“CObject”类中声明)---解决办法
- Install xrdp on CentOS 7 / RHEL 7
- visio 2010如何激活
- CSharp-基本原理-Application.Run()、Application.Run()、Form.ShowDialog()
- Java 语言基础
- Mac 下配置SVN服务器
- 我佩服-WPF(2)