//
// 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. easyui datagrid动态设置行、列、单元格不允许编辑

    Easyui datagrid 行编辑.列编辑.单元格编辑设置 功能: 动态对datagrid 进行行.列.单元格编辑进行设置不允许编辑. 禁用行编辑: 在编辑方法调用前,对选择的行进行判断,如果不允 ...

  2. Swift不等于nil

    我照着书上的例子写下了如下代码,运行后发现提示Nil cannot be assigned to type 'Int' if i!=nil {//Nil cannot be assigned to t ...

  3. linuxubuntu升级.net core版本到2.0

    直接看这里 https://www.microsoft.com/net/core#linuxubuntu

  4. iOS 9应用开发教程之ios9中实现button的响应

    iOS 9应用开发教程之ios9中实现button的响应 IOS9实现button的响应 button主要是实现用户交互的.即实现响应.button实现响应的方式能够依据加入button的不同分为两种 ...

  5. 读取properties属性文件——国际化

    public class PropertiesInfo { /** * PropertiesInfo实例 */ private static PropertiesInfo pi = null; pri ...

  6. 双线机房双网卡双ip 路由设置

    做互联网网站,最头疼的事情之一就是电信和网通的互联互不通了,为了能够让北方网通和南方电信用户都可以快速的访问网站,解决办法就是托管 到双线机房.双线机房有两类,一类是通过BGP技术实现互联互通,服务器 ...

  7. SQL Server 创建和使用索引

    创建索引: (1)在SQL Server Management Studio中,选择并右击要创建索引的表,从弹出菜单中选择“设计”,打开表设计器.右键单击表设计器,从弹出菜单中选择“索引/键”命令,打 ...

  8. 使用PHP创建一个REST API(Create a REST API with PHP)

    译者前言: 首先这是一篇国外的英文文章,非常系统.详尽的介绍了如何使用PHP创建REST API,国内这方面的资料非常非常的有限,而且基本没有可操作性.这篇文章写的非常好,只要对PHP稍有了解的程序员 ...

  9. atitit.流程标准化--- mysql启动不起来的排查流程attilax总结

    atitit.流程标准化--- mysql启动不起来的排查流程attilax总结 1. mysql的启动日志文件 1 2. console方式 1 3. 安装为服务 1 3.1. 使用默认配置文件 1 ...

  10. Struts2动作

    ActionContext 每一个请求的处理都在一个独立的线程中.每一个线程都有一个ActionContext对象.它包括了ValueStack和HttpServletRequest的东西. Stru ...