iOS 百度地图获取当前地理位置
//
// 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 百度地图获取当前地理位置的更多相关文章
- IOS百度地图获取所在的城市名称
笔者的app要实现定位所在省和城市名称,借此总结巩固一下! @interface VenueListVC : BasePageTableViewVC<BMKLocationServiceDele ...
- IOS百度地图之--->第一篇《环境配置与基本使用》
Ios 百度地图SDK简易使用说明:http://developer.baidu.com/map/index.php?title=iossdk 先道歉:对于原来上传的Demo我很抱歉,什么都没有,也没 ...
- iOS百度地图简单使用详解
iOS百度地图简单使用详解 百度地图 iOS SDK是一套基于iOS 5.0及以上版本设备的应用程序接口,不仅提供展示地图的基本接口,还提供POI检索.路径规划.地图标注.离线地图.定位.周边雷达等丰 ...
- iOS百度地图SDK集成详细步骤
1.iOS百度地图下载地址 http://developer.baidu.com/map/index.php?title=iossdk/sdkiosdev-download 根据需要选择不同的版本 ...
- java调用百度地图API依据地理位置中文获取经纬度
百度地图api提供了非常多地图相关的免费接口,有利于地理位置相关的开发,百度地图api首页:http://developer.baidu.com/map/. 博主使用过依据地理依据地理位置中文获取经纬 ...
- iOS百度地图简单使用
本文介绍三种接口: 1.基础地图2.POI检索3.定位 首先是配置环境,有两种方法,方法在官方教程里都有,不再多说 1.使用CocoaPods自动配置[这个方法特别好,因为当你使用CocoaPods配 ...
- iOS百度地图探索
新建工程后,几项准备: 1.工程中一个文件设为.mm后缀 2.在Xcode的Project -> Edit Active Target -> Build -> Linking -&g ...
- iOS 百度地图使用详解
最近仿照美团做了款应用,刚好用到百度地图,高德地图之前用的比较多,只是这个项目的后台服务器是另外一个公司做的,他们用的就是百度地图,现在网上用百度地图的还不算太多,博文也是断断续续的,主要是中间跳跃有 ...
- 百度地图 获取矩形point
http://developer.baidu.com/map/jsdemo.htm#f0_7 鼠标绘制点线面 <!DOCTYPE html><html><head> ...
随机推荐
- C# 异或校验算法
C# 的异或校验算法 直接上代码 public partial class FormCRC : Form { public FormCRC() { InitializeComponent(); } p ...
- docker容器互连
三种方式 1.使用容器连接的示例如下: $ docker run --name some-app --link itbilu-mysql:mysql -d application-that-uses- ...
- SICP 1.23-1.26体会
1.23 代码修改非常easy, 关键是时间. 电脑上算了一下. 100000000下面全是0. 開始还以为代码写错了. 最后没办法, 用1e10 1e11来计算. 发现比 1e11 1e12快1.2 ...
- laravel的模板嵌套循环可以这样调试
@foreach($first as $value) {{ dump($value) }} @endforeach
- unity, itween 对不透明对象使用FadeTo需要先更换material
跟自己实现fade一样,使用itween对不透明对象FadeTo前也要先更换material为透明material. 设player的Hierarchy如下: player --aniRoot --- ...
- 如何通过 AAR 形式集成 leakcanary-android 服务
如何通过 AAR 形式集成 leakcanary-android 服务 如何通过在线引用的方式拿到所有相关的依赖项文件? #1.禁用 Gradle 离线模式 #2.按照文档要求添加项目依赖 #3.Sy ...
- CentOS下安装man手册
1.命令: yum install man 后发现,有的函数仍然没有.经过一番查找,原来安装的不完全,还要执行下面命令: yum install man-pages 2.总结:cengos下安装man ...
- Atitit.用户权限服务 登录退出功能
Atitit.用户权限服务 登录退出功能 参数说明 /com.attilax/user/loginOut.jsp?url="+url Utype=mer 作者:: ★(attilax)&g ...
- [Python]计算闰年时候出现的and和or优先级的问题以及短路逻辑
好吧题目非常easy.可是有些细节还是挺有意思的. 题目是:计算今年是否是闰年,推断闰年条件,满足年份模400为0,或者模4为0可是模100不为0 答案是这种: import time #计算今年是否 ...
- 一点一滴之DBUS
记录几个参考链接: http://www.cnblogs.com/muxue/archive/2012/12/02/2798876.html --- DBus 入门与应用 -- DBus 的 C 编 ...