@interface GroupReportViewController () <BMKMapViewDelegate,BMKLocationServiceDelegate,BMKGeoCodeSearchDelegate,UITableViewDataSource,UITableViewDelegate>

{

BOOL isFirstLocation;

}

@property(nonatomic,strong)BMKMapView* mapView;

@property(nonatomic,strong)BMKLocationService* locService;

@property(nonatomic,strong)BMKGeoCodeSearch* geocodesearch;

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataSource;

@property(nonatomic,assign)CLLocationCoordinate2D currentCoordinate;

@property(nonatomic,assign)NSInteger currentSelectLocationIndex;

@property(nonatomic,strong)UIImageView *centerCallOutImageView;

@property(nonatomic,strong)UIButton *currentLocationBtn;

@end

@implementation GroupReportViewController

- (void)viewDidLoad

{

[super viewDidLoad];

[self.view setBackgroundColor:[UIColor whiteColor]];

[self setTitle:@"定位demo"];

[self configUI];

[self startLocation];

}

-(void)configUI

{

self.mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, kSCREENWIDTH, 300)];

self.mapView.delegate = self;

[self.view addSubview:self.mapView];

self.centerCallOutImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];

self.centerCallOutImageView.center = self.mapView.center;

self.centerCallOutImageView.backgroundColor = [UIColor redColor];

[self.view addSubview:self.centerCallOutImageView];

[self.view bringSubviewToFront:self.centerCallOutImageView];

[self.mapView layoutIfNeeded];

self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 300, kSCREENWIDTH, 200)];

self.tableView.delegate = self;

self.tableView.dataSource = self;

[self.view addSubview:self.tableView];

[self.tableView registerClass:[LocationCell class] forCellReuseIdentifier:@"LocationCell"];

self.currentLocationBtn =[UIButton buttonWithType:UIButtonTypeCustom];

[self.currentLocationBtn setImage:[UIImage imageNamed:@"location_back_icon"] forState:UIControlStateNormal];

[self.currentLocationBtn setImage:[UIImage imageNamed:@"location_blue_icon"] forState:UIControlStateSelected];

[self.currentLocationBtn addTarget:self action:@selector(startLocation) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:self.currentLocationBtn];

[self.view bringSubviewToFront:self.currentLocationBtn];

}

-(void)startLocation

{

isFirstLocation=YES;//首次定位

self.currentSelectLocationIndex=0;

self.currentLocationBtn.selected=YES;

[self.locService startUserLocationService];

self.mapView.showsUserLocation = NO;//先关闭显示的定位图层

self.mapView.userTrackingMode = BMKUserTrackingModeFollow;//设置定位的状态

self.mapView.showsUserLocation = YES;//显示定位图层

}

-(void)startGeocodesearchWithCoordinate:(CLLocationCoordinate2D)coordinate

{

BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];

reverseGeocodeSearchOption.reverseGeoPoint = coordinate;

BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption];

if(flag)

{

NSLog(@"反geo检索发送成功");

}

else

{

NSLog(@"反geo检索发送失败");

}

}

-(void)setCurrentCoordinate:(CLLocationCoordinate2D)currentCoordinate

{

_currentCoordinate=currentCoordinate;

[self startGeocodesearchWithCoordinate:currentCoordinate];

}

-(void)viewWillAppear:(BOOL)animated

{

[self.mapView viewWillAppear];

self.mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放

self.locService.delegate = self;

self.geocodesearch.delegate = self;

}

-(void)viewWillDisappear:(BOOL)animated

{

[self.mapView viewWillDisappear];

self.mapView.delegate = nil; // 不用时,置nil

self.locService.delegate = nil;

self.geocodesearch.delegate = nil;

}

- (void)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

- (void)dealloc

{

if (_mapView)

{

_mapView = nil;

}

if (_geocodesearch)

{

_geocodesearch = nil;

}

if (_locService)

{

_locService=nil;

}

}

#pragma mark - BMKMapViewDelegate

/**

*在地图View将要启动定位时,会调用此函数

*@param mapView 地图View

*/

- (void)willStartLocatingUser

{

NSLog(@"start locate");

}

/**

*用户方向更新后,会调用此函数

*@param userLocation 新的用户位置

*/

- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation

{

[self.mapView updateLocationData:userLocation];

//    NSLog(@"heading is %@",userLocation.heading);

}

/**

*用户位置更新后,会调用此函数

*@param userLocation 新的用户位置

*/

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{

isFirstLocation=NO;

self.currentLocationBtn.selected=NO;

[self.mapView  updateLocationData:userLocation];

self.currentCoordinate=userLocation.location.coordinate;

if (self.currentCoordinate.latitude!=0)

{

[self.locService stopUserLocationService];

}

}

/**

*在地图View停止定位后,会调用此函数

*@param mapView 地图View

*/

- (void)didStopLocatingUser

{

NSLog(@"stop locate");

}

/**

*定位失败后,会调用此函数

*@param mapView 地图View

*@param error 错误号,参考CLError.h中定义的错误号

*/

- (void)didFailToLocateUserWithError:(NSError *)error

{

NSLog(@"location error");

}

- (void)mapView:(BMKMapView *)mapView onClickedMapBlank:(CLLocationCoordinate2D)coordinate

{

NSLog(@"map view: click blank");

}

- (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

{

if (!isFirstLocation)

{

CLLocationCoordinate2D tt =[mapView convertPoint:self.centerCallOutImageView.center toCoordinateFromView:self.centerCallOutImageView];

self.currentCoordinate=tt;

}

}

#pragma mark - BMKGeoCodeSearchDelegate

/**

*返回地址信息搜索结果

*@param searcher 搜索对象

*@param result 搜索结BMKGeoCodeSearch果

*@param error 错误号,@see BMKSearchErrorCode

*/

- (void)onGetGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error

{

NSLog(@"返回地址信息搜索结果,失败-------------");

}

/**

*返回反地理编码搜索结果

*@param searcher 搜索对象

*@param result 搜索结果

*@param error 错误号,@see BMKSearchErrorCode

*/

- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error

{

if (error == BMK_SEARCH_NO_ERROR)

{

[self.dataSource removeAllObjects];

[self.dataSource addObjectsFromArray:result.poiList];

if (isFirstLocation)

{

//把当前定位信息自定义组装 放进数组首位

BMKPoiInfo *first =[[BMKPoiInfo alloc]init];

first.address=result.address;

first.name=@"[当前位置]";

first.pt=result.location;

first.city=result.addressDetail.city;

[self.dataSource insertObject:first atIndex:0];

}

[self.tableView reloadData];

}

}

#pragma mark - TableViewDelegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return self.dataSource.count;

}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

LocationCell*cell =[tableView dequeueReusableCellWithIdentifier:@"LocationCell" ];

BMKPoiInfo *model=[self.dataSource objectAtIndex:indexPath.row];

cell.textLabel.text=model.name;

cell.detailTextLabel.text=model.address;

cell.detailTextLabel.textColor=[UIColor grayColor];

if (self.currentSelectLocationIndex==indexPath.row)

cell.accessoryType=UITableViewCellAccessoryCheckmark;

else

cell.accessoryType=UITableViewCellAccessoryNone;

return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

BMKPoiInfo *model=[self.dataSource objectAtIndex:indexPath.row];

BMKMapStatus *mapStatus =[self.mapView getMapStatus];

mapStatus.targetGeoPt=model.pt;

[self.mapView setMapStatus:mapStatus withAnimation:YES];

self.currentSelectLocationIndex=indexPath.row;

[self.tableView reloadData];

}

#pragma mark - InitMethod

-(BMKMapView*)mapView

{

if (_mapView==nil)

{

_mapView =[BMKMapView new];

_mapView.zoomEnabled=NO;

_mapView.zoomEnabledWithTap=NO;

_mapView.zoomLevel=17;

}

return _mapView;

}

-(BMKLocationService*)locService

{

if (_locService==nil)

{

_locService = [[BMKLocationService alloc]init];

}

return _locService;

}

-(BMKGeoCodeSearch*)geocodesearch

{

if (_geocodesearch==nil)

{

_geocodesearch=[[BMKGeoCodeSearch alloc]init];

}

return _geocodesearch;

}

-(UITableView*)tableView

{

if (_tableView==nil)

{

_tableView=[UITableView new];

_tableView.delegate=self;

_tableView.dataSource=self;

}

return _tableView;

}

-(UIImageView*)centerCallOutImageView

{

if (_centerCallOutImageView==nil)

{

_centerCallOutImageView=[UIImageView new];

[_centerCallOutImageView setImage:[UIImage imageNamed:@"location_green_icon"]];

}

return _centerCallOutImageView;

}

-(NSMutableArray*)dataSource

{

if (_dataSource==nil) {

_dataSource=[[NSMutableArray alloc]init];

}

return _dataSource;

}

@end

ios 微信发送位置的更多相关文章

  1. 利用百度地图Android sdk高仿微信发送位置功能

    接触了百度地图开发平台半个月了,这2天试着模仿了微信给好友发送位置功能,对百度地图的操作能力又上了一个台阶 (假设须要完整demo.请评论留下邮箱) (眼下源代码已经不发送,假设须要源代码.加qq31 ...

  2. iOS 发送位置消息

    发送地理位置在社交应用里面是很常用的需求.最近也需要在自己的应用里面加入这个功能 首先我们需要获取自己的地理位置,这里用到 CLLocationManager 这个类,调用如下代码 locationM ...

  3. iOS微信第三方登录实现

    iOS微信第三方登录实现   一.接入微信第三方登录准备工作.移动应用微信登录是基于OAuth2.0协议标准构建的微信OAuth2.0授权登录系统.在进行微信OAuth2.0授权登录接入之前,在微信开 ...

  4. IOS微信分享功能简单实现

    PS:此文以简单实现功能为主,不足之前还望指点,大神勿喷. 在此之前如何申请微信认证的Key就不说了,公司一般会有人搞 1.首先下载微信SDK:微信SDK下载地址(更多关于微信SDK信息文档请访问官方 ...

  5. zabbix使用企业微信发送告警信息

    用qq邮箱发送告警信息一点都不方便,看到网上说也可以使用微信发送告警信息,所以就试了一下. 首先先试着在虚拟主机上给微信发送信息. 我们需要注册企业微信,注册时有一个地方需要注意,就是注册时选择组织, ...

  6. iOS微信实现第三方登录的方法

    这篇文章主要介绍了iOS微信第三方登录实现的全过程,一步一步告诉大家iOS微信实现第三方登录的方法,感兴趣的小伙伴们可以参考一下   一.接入微信第三方登录准备工作.移动应用微信登录是基于OAuth2 ...

  7. iOS微信支付集成

    概述 iOS微信支付集成 详细 代码下载:http://www.demodashi.com/demo/10735.html 支付宝和微信都是业界的老大哥,相信大家都有所觉得文档.SDK都是各种坑吧(纯 ...

  8. 【转】odoo 10的企业微信发送程序介绍

    本文介绍的微信发送程序不是独立的模块,是某企业应用的一部分, 源码可在京津冀odoo技术交流群的群共享中下载.   [1]基本配置 在work.weixin.qq.com上注册一个企业后,会得到企业的 ...

  9. ios xmpp 发送语音图片解决方案

    ios xmpp 发送语音,图片解决方案,有需要的朋友可以参考下. 目前做IM多是用的xmpp. 因为项目需求需要实现语音和图片的发送. 发送语音图片有三种方法. 1,xmpp smack.文件传输方 ...

随机推荐

  1. xml格式发送

    1. namespace xml格式发送 { /// <summary> /// 实体转Xml,Xml转实体类 /// </summary> /// <typeparam ...

  2. 设置VisualSVN在提交修改时必须输入一定数量的备注信息

    我发现在使用SVN中,提交时,很多人不习惯填写备注信息,虽然在培训中.平时使用时多次提醒备注信息的好处,但是效果不大,每次提交时还是不写,或者随便写两字. 所以很有必要通过系统设置强制填写足够数量的备 ...

  3. github上比較好的开源项目(持续更新)

    1:https://github.com/Skykai521/StickerCamera 实现相机功能 实现对图片进行裁剪的功能 图片的滤镜功能 能为图片加入贴纸(贴纸可移动,放大,旋转) 能为图片加 ...

  4. 在Ubuntu 16.04下安装 virtualbox 5.2

        sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian xenial contrib" ...

  5. homebrew可以管理众多开源软件的安装和卸载

    通过homebrew可以管理众多开源软件的安装和卸载. 参考https://github.com/mxcl/homebrew/wiki 1. 安装: ruby -e "$(curl -fsS ...

  6. Hibernate3中generator标签使用

    在XXX.hbm.xml映射配置文件中定义<generator class="native"/>标签是为了告诉Hibernate框架使用什么方式去生成主键class对应 ...

  7. PHP Memcached 面试题

    这里收集了经常被问到的关于memcached的问题 * memcached是怎么工作的? * memcached最大的优势是什么? * memcached和MySQL的query cache相比,有什 ...

  8. UFLDL深度学习笔记 (五)自编码线性解码器

    UFLDL深度学习笔记 (五)自编码线性解码器 1. 基本问题 在第一篇 UFLDL深度学习笔记 (一)基本知识与稀疏自编码中讨论了激活函数为\(sigmoid\)函数的系数自编码网络,本文要讨论&q ...

  9. 为什么使用JSP?

    JSP程序与CGI程序有着相似的功能,但和CGI程序相比,JSP程序有如下优势: 性能更加优越,因为JSP可以直接在HTML网页中动态嵌入元素而不需要单独引用CGI文件. 服务器调用的是已经编译好的J ...

  10. js 抢月饼

    面源码: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" co ...