//
// ViewController.m
// BaiDuDemo
//
// Created by Chocolate. on 15-3-2.
// Copyright (c) 2015年 redasen. All rights reserved.
// #import "ViewController.h"
#import "BMapKit.h" @interface ViewController () <BMKGeoCodeSearchDelegate,BMKMapViewDelegate, BMKLocationServiceDelegate>
@property (strong, nonatomic) BMKMapView *mapView;
@property (strong, nonatomic) BMKGeoCodeSearch *search;
@property (strong, nonatomic) BMKLocationService *locService;
@end @implementation ViewController
{
BMKUserLocation *myLocation;
} - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_mapView = [[BMKMapView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:_mapView]; _search = [[BMKGeoCodeSearch alloc]init]; //初始化BMKLocationService
_locService = [[BMKLocationService alloc]init];
_locService.delegate = self;
//启动LocationService
[_locService startUserLocationService];
} -(void)viewWillAppear:(BOOL)animated
{
[_mapView viewWillAppear];
_mapView.delegate = self;
_search.delegate = self;
} -(void)viewDidAppear:(BOOL)animated
{
[_mapView setShowsUserLocation:YES];
} -(void)viewWillDisappear:(BOOL)animated
{
[_mapView setShowsUserLocation:NO];
_mapView.delegate = nil;
_search.delegate = nil;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark - BMKLocationServiceDelegate
/**
*在将要启动定位时,会调用此函数
*/
- (void)willStartLocatingUser
{ } /**
*在停止定位后,会调用此函数
*/
- (void)didStopLocatingUser
{
CLLocationCoordinate2D pt = (CLLocationCoordinate2D){, }; pt = (CLLocationCoordinate2D){myLocation.location.coordinate.latitude, myLocation.location.coordinate.longitude}; BMKReverseGeoCodeOption *option = [[BMKReverseGeoCodeOption alloc]init];
option.reverseGeoPoint = pt;
BOOL result = [_search reverseGeoCode:option]; if(result)
{
NSLog(@"反geo检索发送成功");
}
else
{
NSLog(@"反geo检索发送失败");
}
} /**
*用户方向更新后,会调用此函数
*@param userLocation 新的用户位置
*/
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
NSLog(@"heading is %@",userLocation.heading);
} /**
*用户位置更新后,会调用此函数
*@param userLocation 新的用户位置
*/
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
if (userLocation != nil) { NSLog(@"get location success");
myLocation = userLocation;
_mapView.showsUserLocation = NO;
[_locService stopUserLocationService];
} NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
} /**
*定位失败后,会调用此函数
*@param error 错误号
*/
- (void)didFailToLocateUserWithError:(NSError *)error
{ } #pragma mark - BMKGeoCodeSearchDelegate /**
*返回地址信息搜索结果
*@param searcher 搜索对象
*@param result 搜索结BMKGeoCodeSearch果
*@param error 错误号,@see BMKSearchErrorCode
*/
- (void)onGetGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{ } /**
*返回反地理编码搜索结果
*@param searcher 搜索对象
*@param result 搜索结果
*@param error 错误号,@see BMKSearchErrorCode
*/
- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:result.address delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:nil, nil];
[alert show];
} @end

iOS 百度地图获取当前地理位置的更多相关文章

  1. IOS百度地图获取所在的城市名称

    笔者的app要实现定位所在省和城市名称,借此总结巩固一下! @interface VenueListVC : BasePageTableViewVC<BMKLocationServiceDele ...

  2. IOS百度地图之--->第一篇《环境配置与基本使用》

    Ios 百度地图SDK简易使用说明:http://developer.baidu.com/map/index.php?title=iossdk 先道歉:对于原来上传的Demo我很抱歉,什么都没有,也没 ...

  3. iOS百度地图简单使用详解

    iOS百度地图简单使用详解 百度地图 iOS SDK是一套基于iOS 5.0及以上版本设备的应用程序接口,不仅提供展示地图的基本接口,还提供POI检索.路径规划.地图标注.离线地图.定位.周边雷达等丰 ...

  4. iOS百度地图SDK集成详细步骤

    1.iOS百度地图下载地址 http://developer.baidu.com/map/index.php?title=iossdk/sdkiosdev-download 根据需要选择不同的版本  ...

  5. java调用百度地图API依据地理位置中文获取经纬度

    百度地图api提供了非常多地图相关的免费接口,有利于地理位置相关的开发,百度地图api首页:http://developer.baidu.com/map/. 博主使用过依据地理依据地理位置中文获取经纬 ...

  6. iOS百度地图简单使用

    本文介绍三种接口: 1.基础地图2.POI检索3.定位 首先是配置环境,有两种方法,方法在官方教程里都有,不再多说 1.使用CocoaPods自动配置[这个方法特别好,因为当你使用CocoaPods配 ...

  7. iOS百度地图探索

    新建工程后,几项准备: 1.工程中一个文件设为.mm后缀 2.在Xcode的Project -> Edit Active Target -> Build -> Linking -&g ...

  8. iOS 百度地图使用详解

    最近仿照美团做了款应用,刚好用到百度地图,高德地图之前用的比较多,只是这个项目的后台服务器是另外一个公司做的,他们用的就是百度地图,现在网上用百度地图的还不算太多,博文也是断断续续的,主要是中间跳跃有 ...

  9. 百度地图 获取矩形point

    http://developer.baidu.com/map/jsdemo.htm#f0_7  鼠标绘制点线面 <!DOCTYPE html><html><head> ...

随机推荐

  1. 解决在IE9,IE10浏览器下,程序没有任何错误,easy ui页面不加载任何数据的问题

    对于web应用程序,经常用到开发人员工具,按F12,可以调试脚本,可以查看监视网络,查看各页面加载时间,非常方便,今天在调试js时,不小心打开了兼容性视图, 之后每次打打开页面时,均不显示页面post ...

  2. vue cli3.0 build 打包 的 js 文件添加版本号 解决 js 缓存问题

    在 vue.config.js 的文件中加入下面这段话 // vue.config.jsconst Timestamp = new Date().getTime();module.exports = ...

  3. .Net程序员面试 每个人都应知道篇 (回答Scott Hanselman的问题)

    昨天回答了Scott Hanselman在他清单上关于C#那部分的题目,.Net 程序员面试 C# 语言篇 (回答Scott Hanselman的问题),今天接着回答他在清单上列出的"每个写 ...

  4. 利用putty的pscp命令上传文件

    1.有的时候,本地下载源码包的速度快过vps(主要指国内),那么可以用迅雷下载后上传到vps. 2.为了这么点事情,专门安装一个ftp软件,太麻烦,于是想到了putty贴心的pscp小程序. 3.首先 ...

  5. CentOS下安装man手册

    1.命令: yum install man 后发现,有的函数仍然没有.经过一番查找,原来安装的不完全,还要执行下面命令: yum install man-pages 2.总结:cengos下安装man ...

  6. 音频采样中left-or right-justified(左对齐,右对齐), I2S时钟关系

    音频采样中left-or right-justified(左对齐,右对齐), I2S时钟关系 原创 2014年02月11日 13:56:51 4951 0 0 刚刚过完春节,受假期综合症影响脑袋有点发 ...

  7. url参数

    两个参数情况: String url="http://59.78.93.208:9097/Order?id="+id+"&value="+value; ...

  8. java集成开发环境常用操作集

    1.简单搭建maven集成开发环境 一.     Jetty安装 下载地址(包涵windows和Linux各版本,Jetty9需要JDK7):http://download.eclipse.org/j ...

  9. Android之2D图形(圆、直线、点)工具类 (持续更新)

    public class Circle { private PointF centerPoint; private float radius; public PointF getCenterPoint ...

  10. NGUI3.7.4实现循环拖动

    前段时间下了NGUI新版本3.7.4,看到例子Endless Scroll Views,实现了循环拖动,可能会用到,先把实现步骤贴出来跟大家分享一下. 1.首先新建一个背景. 2.添加所需控件,类似滑 ...