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. 估计百度的 ...
随机推荐
- GCC KEIL ARM编译器
经常用keil,也听说IAR的编译效率很高,原来C51时用proteus,最近proteus8开始支持stm32,所以在研究用keil5+HAL+proteus学习STM32F. 问题:因为prote ...
- qconbeijing2014
http://2014.qconbeijing.com/videoslides.html 周一 周二 周三 周四 周五 周六 2014年5月19日 Deep Dive into Amazon's ...
- P3717 [AHOI2017初中组]cover
题目背景 以下为不影响题意的简化版题目. 题目描述 一个n*n的网格图上有m个探测器,每个探测器有个探测半径r,问这n*n个点中有多少个点能被探测到. 输入输出格式 输入格式: 第一行3个整数n,m, ...
- Redis学习笔记1-安装配置
一.Redis安装 Redis官网:http://www.redis.io/download 注意:版本号2.4,2.6,2.8等偶数结尾为稳定版,2.5等为非稳定版本,生成环境应该使用稳定版 下载解 ...
- AJPFX总结string类和简单问题
String表示字符串,所谓字符串,就是一连串的字符;String是不可变类,一旦String对象被创建,包含在对象中的字符序列(内容)是不可变的,直到对象被销毁://一个String对象的内容不能变 ...
- CF963A Alternating Sum
思路:利用周期性转化为等比数列求和. 注意当a != b的时候 bk * inv(ak) % (109 + 9)依然有可能等于1,不知道为什么. 实现: #include <bits/stdc+ ...
- 【学习笔记】二:在HTML中使用JavaScript
1.<script>标签 1)考虑到最大限度的浏览器兼容性和约定俗成,type属性使用:text/javascript. 2)标签建议放置到</body>标签前,提高用户体验( ...
- Synplify FPGA 逻辑综合
作为 Synopsys FPGA 设计解决方案的一部分,Synplify FPGA 综合软件是实现高性能.高性价比的 FPGA 设计的行业标准. 其独特的行为提取综合技术 (Behavior Extr ...
- Java Script 学习笔记(一)
示例如下: JavaScript-警告(alert 消息对话框) 我们在访问网站的时候,有时会突然弹出一个小窗口,上面写着一段提示信息文字.如果你不点击“确定”,就不能对网页做任何操作,这个小窗口就是 ...
- K-means算法Java实现
public class KMeansCluster { private int k;//簇的个数 private int num = 100000;//迭代次数 ...