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

//
// 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. C51之数据范围

    在C51中各数据类型的范围如下:如果宏常量大于65536,则要加UL后缀:乘法运算不能只将结果强制类型转换,而应在被乘数前加(unsigned long)强制转换. 2 因为RAM有限,所以运算量大的 ...

  2. 生产环境中配置的samba

    实验需求: 由于实验室纳新一帮新孩子,搭建samba主要是临时共享一些学习资源的,基本上大家用的都是windows.而且这个服务可以让他们在校园的里的个个角落都可以访问到,所以给挂了学校的公网,不过我 ...

  3. Java关键字-volatile

    关键字volatile可以说是Java虚拟机提供的最轻量级的同步机制. 一旦某个共享变量(类的成员变量.类的静态成员变量)被volatile修饰之后,那么就具备了两层语义: 1.保证了不同线程对这个变 ...

  4. Elasticsearch (2) - 映射

    常用映射类型 核心的字段类型如下: String 字符串包括text和keyword两种类型: 1.text analyzer 通过analyzer属性指定分词器. 下边指定name的字段类型为tex ...

  5. Hibernate懒加载深入分析

    Hibernate懒加载深入分析 懒加载可以提高性能吗?  不可以简单的说"能",因为Hibernate的关系映射拖累了SQL的性能,所以想出懒加载来弥补.只是弥补而以,不会超越. ...

  6. SQL——将两列合并成一列

    将两列合并连接成一列,需要注意的是列的格式必须是NVARCHAR或者VARCHAR类型 ), call_uuid, ) +','+agent_code '   PerDate 1 ,980408102 ...

  7. react基础语法(一)元素渲染和基础语法规则

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. 【OpenCV】motion blur 的简单实现

    先推荐界面比较丑,但是还不错的在线图片处理网站: http://www168.lunapic.com/editor/ 由于最近在做毕设了,结合前面关于图像处理和机器学习的操作,想做一些好玩的东西,其中 ...

  9. (译)IOS block编程指南 2 block开始

    Getting Started with Blocks(开始block) The following sections help you to get started with blocks usin ...

  10. 【搜索】P1032 字串变换

    题目描述 已知有两个字串A,B及一组字串变换的规则(至多6个规则): A1​ ->B1​ A2​ -> B2​ 规则的含义为:在 A中的子串 A1​ 可以变换为B1​,A2​ 可以变换为  ...