iOS第三方地图-百度地图中心点定位
使用百度地图定位后,滑动地图,使用反编码确定地图中心店的位置信息
//
// MapControl.m
// quyizu
//
// Created by apple on 15/9/2.
// Copyright (c) 2015年 waste. All rights reserved.
// //使用百度地图定位,poi搜索,地理编码功能
#import "MapControl.h"
#import "WJBaiduMapTools.h"
@interface MapControl ()<BMKPoiSearchDelegate,BMKMapViewDelegate,BMKGeoCodeSearchDelegate,BMKLocationServiceDelegate>{
BMKMapView *_mapView; //地图
BMKPoiSearch *_poisearch; //poi搜索
BMKGeoCodeSearch *_geocodesearch; //geo搜索服务
CGFloat _longitude; //经度
CGFloat _latitude; //纬度
UILabel *_labelShow; //信息显示
NSInteger _index; //判断次数
BMKLocationService* _locService;
UIImageView *_viewCenterBG;
} @end @implementation MapControl - (instancetype)init
{
self = [super init];
if (self) {
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(rightItemPressed)];
self.navigationItem.rightBarButtonItem = rightItem;
}
return self;
} - (void)rightItemPressed {
[self.navigationController popViewControllerAnimated:YES];
if ([_delegate respondsToSelector:@selector(mapControlDelegate:isSchool:)]) {
[_delegate mapControlDelegate:_labelShow.text isSchool:_isSchool];
}
} - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_mapView.delegate = self;
_geocodesearch.delegate = self;
_locService.delegate = self;
}
-(void)viewWillDisappear:(BOOL)animated
{
_mapView.delegate = nil; // 不用时,置nil
_poisearch.delegate = nil; // 不用时,置nil
_geocodesearch.delegate = nil;
_locService.delegate = nil;
} - (void)dealloc {
if (_geocodesearch != nil) {
_geocodesearch = nil;
}
if (_mapView) {
_mapView = nil;
}
} - (void)viewDidLoad {
[super viewDidLoad];
if (_isSchool) {
[self addnavigationTitle:@"上学方便"];
}else {
[self addnavigationTitle:@"工作方便"];
}
_mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(, , ScreenWidth, ScreenHeight)];
[_mapView setZoomLevel:];
[self.view addSubview:_mapView]; _geocodesearch = [[BMKGeoCodeSearch alloc]init];
_locService = [[BMKLocationService alloc]init];
[_locService startUserLocationService];
[self initCenterView];
} - (void)initCenterView {
UIView *viewBG = [[UIView alloc]initWithFrame:CGRectMake(, , ScreenWidth, )];
[self.view addSubview:viewBG]; UIView *viewBGalpha = [[UIView alloc]initWithFrame:viewBG.bounds];
viewBGalpha.backgroundColor = [UIColor blackColor];
viewBGalpha.alpha = 0.4;
[viewBG addSubview:viewBGalpha]; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(, , ScreenWidth-, )];
label.textAlignment = NSTextAlignmentCenter;
label.text = @"地图显示";
label.numberOfLines = ;
label.font = [UIFont systemFontOfSize:];
label.textColor = [UIColor whiteColor];
[viewBG addSubview:label];
_labelShow = label; UIImageView *viewCenterBG = [[UIImageView alloc]init];
viewCenterBG.image = [UIImage imageNamed:@"map_iconBG"];
viewCenterBG.center = CGPointMake(ScreenWidth/, ScreenHeight/);
viewCenterBG.bounds = CGRectMake(, , , );
viewCenterBG.alpha = 0.5;
_viewCenterBG= viewCenterBG;
[self.view addSubview:viewCenterBG]; [NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(timerPressed) userInfo:nil repeats:YES]; UIView *view = [[UIView alloc]init];
view.center = CGPointMake(ScreenWidth/, ScreenHeight/);
view.bounds = CGRectMake(, , , );
view.layer.cornerRadius = 7.5;
view.layer.borderWidth = ;
view.layer.borderColor = [UIColor whiteColor].CGColor;
view.layer.masksToBounds = YES;
view.backgroundColor = [UIColor colorWithHexString:@"69c9fa"];
[self.view addSubview:view];
} - (void)timerPressed {
[UIView animateWithDuration: animations:^{
_viewCenterBG.bounds = CGRectMake(, , , );
_viewCenterBG.alpha = 0.1;
} completion:^(BOOL finished) {
[UIView animateWithDuration: animations:^{
_viewCenterBG.bounds = CGRectMake(, , , );
_viewCenterBG.alpha = 0.5;
}];
}];
} #pragma mark - 根据经纬度搜索 - (void)reverseGeoPointSearchlongitude:(CGFloat )longitude latitude:(CGFloat)latitude{ CLLocationCoordinate2D pt = (CLLocationCoordinate2D){, };
pt = (CLLocationCoordinate2D){latitude, longitude};
BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
reverseGeocodeSearchOption.reverseGeoPoint = pt;
BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption];
if(flag)
{
NSLog(@"反geo检索发送成功");
}
else
{
NSLog(@"反geo检索发送失败");
}
} #pragma mark - BMKMapViewDelegate //地图改变完成调用这个接口
- (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { if (_longitude == mapView.centerCoordinate.longitude &&_latitude == mapView.centerCoordinate.latitude) { }else {
if (_index !=) {
[self reverseGeoPointSearchlongitude:mapView.centerCoordinate.longitude latitude:mapView.centerCoordinate.latitude];
_longitude = mapView.centerCoordinate.longitude;
_latitude = mapView.centerCoordinate.latitude;
}
}
NSLog(@"%f,%f",mapView.centerCoordinate.longitude,mapView.centerCoordinate.latitude);
} #pragma mark - BMKGeoCodeSearchDelegate // *返回反地理编码搜索结果
- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error {
if (error == ) {
BMKPointAnnotation* item = [[BMKPointAnnotation alloc]init];
item.coordinate = result.location;
item.title = result.address;
if (_index == ) {
_mapView.centerCoordinate = result.location;
_index ++;
}
NSString* titleStr;
NSString* showmeg;
titleStr = @"反向地理编码";
showmeg = [NSString stringWithFormat:@"%@",item.title];
_labelShow.text = showmeg;
}
}
#pragma mark - BMKLocationServiceDelegate - (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation {
[_locService stopUserLocationService];
[self reverseGeoPointSearchlongitude:userLocation.location.coordinate.longitude latitude:userLocation.location.coordinate.latitude];
} @end
iOS第三方地图-百度地图中心点定位的更多相关文章
- IOS中使用百度地图定位后获取城市坐标,城市名称,城市编号信息
IOS中使用百度地图定位后获取城市坐标,城市名称,城市编号信息 /**当获取到定位的坐标后,回调函数*/ - (void)didUpdateBMKUserLocation:(BMKUserLocati ...
- iOS开发---集成百度地图完善版
一.成为百度的开发者.创建应用 http://developer.baidu.com/map/index.php?title=首页 (鼠标移向 然后选择你的项目需要的功能 你可以在里面了解到你想要使用 ...
- 通过百度地图API定位--第三方开源--百度地图(一)
1.把百度地图定位API(下载地址:http://lbsyun.baidu.com/sdk/download?selected=location)里面的libs复制到自己的项目libs里面 2.进行相 ...
- IOS苹果和百度地图的相关使用
iOS中使用较多的3款地图,google地图.百度地图.苹果自带地图(高德).其中苹果自带地图在中国使用的是高德的数据.苹果在iOS 6之后放弃了使用谷歌地图,而改用自家的地图.在国内使用的较多的就是 ...
- iOS开发之百度地图导航
本篇主要讲述百度地图的导航功能: 第一步:在使用百度导航之前,我们需要在百度地图开放平台上下载导航的 SDK,共85.8M,网速不好的同学可提前准备好. 第二步:引入导航所需的系统包 将AudioTo ...
- iOS开发---集成百度地图,位置偏移问题
iOS 集成百度SDK 请参考 百度地图官方文档 ,这里不就多啰嗦了 本文介绍的是在百度地图上根据经纬度,自定义气泡时,气泡位置的偏移,在我们天朝这种事是很常见的,也见怪不怪了,在项目中使用的百度地图 ...
- iOS开发---集成百度地图
由于iOS MapKit框架很多情况并不能满足我们的需求,我们可以选择集成百度地图,那该如何操作呢? 申请Key 登录百度API管理中心申请Key http://lbsyun.baidu.com/ap ...
- 通过百度地图API实现搜索地址--第三方开源--百度地图(三)
搜索地址功能是建立在能够通过百度地图API获取位置的基础上 通过百度地图定位获取位置详情:http://www.cnblogs.com/zzw1994/p/5008134.html package c ...
- 通过百度地图API显示当前位置在地图上(图标显示)--第三方开源--百度地图(二)
1.下载百度地图的demo,下载地址:http://lbsyun.baidu.com/sdk/download?selected=mapsdk_basicmap,mapsdk_searchfuncti ...
- 在iOS中使用百度地图
就如同在百度地图的文档中所说的一样,这么来.但是,有一个小疏忽. 到添加完所需要的framework之后,一定要记得把你的(Class-Prefix)AppDelegate的后缀改成mm. 估计百度的 ...
随机推荐
- hashTable 和 hashMap的区别
HashMap是Hashtable的轻量级实现(非线程安全的实现),他们都完成了Map接口,HashMap把Hashtable的contains方法去掉了,改成containsvalue和contai ...
- json字符串和字典类型的相互转换
在开发过程中,有时候需要将json字符串转为字典类型,反之亦然,通常采用.Net的开源类库Newtonsoft.Json进行序列化,这里我也是采用这个,不过我更喜欢写扩展方法方便在项目的调用. 首先新 ...
- mysql对库,表及记录的增删改查
破解密码 #1.关闭mysqlnet stop mysqlmysql还在运行时需要输入命令关闭,也可以手动去服务关闭 #2.重新启动mysqld --skip-grant-tables跳过权限 #3m ...
- BigDecimal取余运算
取余运算在编程中运用非常广泛,对于BigDecimal对象取余运算可以通过divideAndRemainder方法实现. public BigDecimal[] divideAndRemainder( ...
- 基于 Web 的 Go 语言 IDE - Wide 1.5.0 发布!
Wide 是什么 Wide 是一个基于 Web 的 Go 语言团队 IDE. 在线开发:打开浏览器就可以进行开发.全快捷键 智能提示:代码自动完成.查看表达式.编译反馈.Lint 实时运行:极速编译. ...
- 在vscode中显示空格和tab符号
转自:https://blog.csdn.net/bmzk123/article/details/86501706 使用python时最烦人的就是代码对齐,而且tab和空格还不一样,为了便于对其,希望 ...
- Clean Code 第十章 : 类
最近的CleanCode读到了第十章.这一张主要讲了如何去构造一个类,感觉的CleanCode至此已经不仅仅是单纯的讲如何'写'出漂亮的代码,而是从设计方向上去构造出好的代码了. 本章节主要讲了: * ...
- Selenium私房菜系列1 -- Selenium简介
一.Selenium是什么? Selenium是ThroughtWorks公司一个强大的开源Web功能测试工具系列,本系列现在主要包括以下4款: 1.Selenium Core:支持DHTML的测试案 ...
- 在SQLServer使用触发器实现数据完整性
1.实现数据完整性的手段 在sqlserver中,在服务器端实现数据完整性主要有两种手段:一种是在创建表时定义数据完整性,主要分为:实体完整性.域完整性.和级联参照完整性:实现的手段是创建主键约束.唯 ...
- 原创:四种Linux系统开机启动项优命令超给力超详细详解
老葵花哥哥又开课了 接下来是你们的齐天大圣孙悟空给你们带来的详细版Linux系统开机启动优化四种命令 第一种方法是很正常的 第二种有点难理解 第三种来自我的一个奇思妙想 本文档秉承 不要钱也不要臀部的 ...