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

//
// 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. 162 Find Peak Element 寻找峰值

    峰值元素是指其值大于左右相邻值的元素.给定一个输入数组,其中 num[i] ≠ num[i+1],找到峰值元素并返回其索引.数组可能包含多个峰值,在这种情况下,返回到任何一个峰值所在位置都可以.你可以 ...

  2. Backbone学习记录(7)

    事件委托 <form> <input type="text" class="txt"> <input type="but ...

  3. Java断点续传(基于socket与RandomAccessFile的简单实现)

    Java断点续传(基于socket与RandomAccessFile的简单实现) 这是一个简单的C/S架构,基本实现思路是将服务器注册至某个空闲端口用来监视并处理每个客户端的传输请求. 客户端先获得用 ...

  4. poj3616 Milking Time

    思路: dp. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...

  5. Apache CXF 框架结构和基本原理

    CXF旨在为服务创建必要的基础设施,它的整体架构主要由以下几个部分组成: 1.Bus 它是C X F架构的主干,为共享资源提供了一个可配置的场所,作用非常类似于S p r i n g的Applicat ...

  6. Git理论知识补充

    转自: http://www.cnblogs.com/hnrainll/archive/2012/11/13/2768003.html 对于任何一个文件,在 Git 内都只有三种状态:已提交(comm ...

  7. (转)Spring提供的CharacterEncoding和OpenSessionInView功能

    http://blog.csdn.net/yerenyuan_pku/article/details/52902282 前面我们以一种更加优雅的方式集成了Spring4.2.5+Hibernate4. ...

  8. java项目部署jar包

    1. 先将打包成jar包 2. 查看所有的java进程   pgrep java 3. 杀死进程 kill   -9 程序号 4.执行命令  nohup java -jar admin.jar > ...

  9. Microsoft Project 2010基础使用方法

    5.1 项目管理与Microsoft Project2010 Microsoft Project2010深受广大项目管理工程师的青睐. 5.1.1 项目管理的概念 项目管理是项目管理者在有限的资源约束 ...

  10. Wow64

    翻译自Wikipedia: WoW64 运行在微软平台上,WoW64(Windows 32-bit on Windows 64-bit) 是一个Windows的子操作系统, 它能运行32位的应用,在所 ...