使用百度地图定位后,滑动地图,使用反编码确定地图中心店的位置信息

//
// 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第三方地图-百度地图中心点定位的更多相关文章

  1. IOS中使用百度地图定位后获取城市坐标,城市名称,城市编号信息

    IOS中使用百度地图定位后获取城市坐标,城市名称,城市编号信息 /**当获取到定位的坐标后,回调函数*/ - (void)didUpdateBMKUserLocation:(BMKUserLocati ...

  2. iOS开发---集成百度地图完善版

    一.成为百度的开发者.创建应用 http://developer.baidu.com/map/index.php?title=首页 (鼠标移向 然后选择你的项目需要的功能 你可以在里面了解到你想要使用 ...

  3. 通过百度地图API定位--第三方开源--百度地图(一)

    1.把百度地图定位API(下载地址:http://lbsyun.baidu.com/sdk/download?selected=location)里面的libs复制到自己的项目libs里面 2.进行相 ...

  4. IOS苹果和百度地图的相关使用

    iOS中使用较多的3款地图,google地图.百度地图.苹果自带地图(高德).其中苹果自带地图在中国使用的是高德的数据.苹果在iOS 6之后放弃了使用谷歌地图,而改用自家的地图.在国内使用的较多的就是 ...

  5. iOS开发之百度地图导航

    本篇主要讲述百度地图的导航功能: 第一步:在使用百度导航之前,我们需要在百度地图开放平台上下载导航的 SDK,共85.8M,网速不好的同学可提前准备好. 第二步:引入导航所需的系统包 将AudioTo ...

  6. iOS开发---集成百度地图,位置偏移问题

    iOS 集成百度SDK 请参考 百度地图官方文档 ,这里不就多啰嗦了 本文介绍的是在百度地图上根据经纬度,自定义气泡时,气泡位置的偏移,在我们天朝这种事是很常见的,也见怪不怪了,在项目中使用的百度地图 ...

  7. iOS开发---集成百度地图

    由于iOS MapKit框架很多情况并不能满足我们的需求,我们可以选择集成百度地图,那该如何操作呢? 申请Key 登录百度API管理中心申请Key http://lbsyun.baidu.com/ap ...

  8. 通过百度地图API实现搜索地址--第三方开源--百度地图(三)

    搜索地址功能是建立在能够通过百度地图API获取位置的基础上 通过百度地图定位获取位置详情:http://www.cnblogs.com/zzw1994/p/5008134.html package c ...

  9. 通过百度地图API显示当前位置在地图上(图标显示)--第三方开源--百度地图(二)

    1.下载百度地图的demo,下载地址:http://lbsyun.baidu.com/sdk/download?selected=mapsdk_basicmap,mapsdk_searchfuncti ...

  10. 在iOS中使用百度地图

    就如同在百度地图的文档中所说的一样,这么来.但是,有一个小疏忽. 到添加完所需要的framework之后,一定要记得把你的(Class-Prefix)AppDelegate的后缀改成mm. 估计百度的 ...

随机推荐

  1. .net core跨域设置

    services.AddCors(options => options.AddPolicy("AllowSameDomain", builder => builder. ...

  2. 动手实现 React-redux(一):初始化工程

    可以看到 Redux 并不复杂,它那些看起来匪夷所思的设定其实都是为了解决特定的问题而存在的,我们把问题想清楚以后就不难理解它的那些奇怪的设定了.这节开始我们来看看如何把 Redux 和 React. ...

  3. 【转】java编程思想第20章的注解例子用到的com.sun.mirror的jar包

    Java編程思想>中的注解代码中引入过这么一个包(com.sun.mirror),书上说的是在Jdk中有个tools.jar中,引入这个包就每这个问题了,但是笔者用的是JDK 1.8,把这个包i ...

  4. LN : leetcode 733 Flood Fill

    lc 733 Flood Fill 733 Flood Fill An image is represented by a 2-D array of integers, each integer re ...

  5. 生成器的send方法

    send 和next区别 next:唤醒并继续执行 send:唤醒并继续执行 发送信息到生成器内部. def fib(max): n,a,b = 0,0,1 while n < max: msg ...

  6. [转]Qt 5.5 操作 Excel 的速度 效率问题

    转自:http://blog.csdn.net/li494816491/article/details/50274305 1. QAxObject *_excelObject1 =newQAxObje ...

  7. Git 版本控制系统的基本使用、常用操作

    以Ubuntu16.04操作系统为例(其他系统类似),主要记录常用的.基本操作: 0. 安装Git 分散型版本控制系统(CVS): sudo apt-get install git 1. 初始化本地配 ...

  8. 关于js中的then(盗)

    then()相关的东西包括但不限于:promise,thien.js 虽然还没彻底搞清楚这些个玩意儿,但是  现在知道了  then()是干嘛的了 最主要的,是解决了异步方法立刻返回的问题  这个特性 ...

  9. Bootstrap 3 Glyphicons are not working

    Bootstrap 3 Glyphicons are not working 解答1 Note to readers: be sure to read @user2261073's comment a ...

  10. pycharm 用远程环境时报错bash: line 0: cd: /home/tmp: No such file or directory

    delete redundant path