简易的IOS位置定位服务
有时一些小的需求,其实只是需要得知当前IOS APP使用的地点,有些只是想精确到城市级别,并不需要任何地图。
有了以下的简易实现:
@interface MainViewController ()<CLLocationManagerDelegate>
....
@end
@implementation MainViewController
- (void)InitLocation {
//初始化定位服务管理对象
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
self.locationManager.distanceFilter = 1000.0f;
}
/*
其中位置的精确性有如下几个级别,越是精确,程序回调就越慢!当前的例子只是到城市级别,所以使用kCLLocationAccuracyThreeKilometers
extern const CLLocationAccuracy kCLLocationAccuracyBestForNavigation __OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_4_0);
extern const CLLocationAccuracy kCLLocationAccuracyBest;
extern const CLLocationAccuracy kCLLocationAccuracyNearestTenMeters;
extern const CLLocationAccuracy kCLLocationAccuracyHundredMeters;
extern const CLLocationAccuracy kCLLocationAccuracyKilometer;
extern const CLLocationAccuracy kCLLocationAccuracyThreeKilometers;
*/
- (void) viewWillAppear:(BOOL)animated{
//开始定位
if(isSetAddress == FALSE){
dispatch_async(dispatch_get_main_queue(), ^{
[self InitLocation];
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager startUpdatingLocation];
});
}
}
#pragma mark Core Location委托方法用于实现位置的更新,可以得到经纬度,省、城市、街道
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:
(NSArray *)locations
{
CLLocation * currLocation = [locations lastObject];
NSLog(@"latitude=%3.5f, longitude=%3.5f, altitude=%3.5f", currLocation.coordinate.latitude, currLocation.coordinate.longitude, currLocation.altitude);
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:currLocation
completionHandler:^(NSArray *placemarks, NSError *error) {
if ([placemarks count] > 0) {
CLPlacemark *placemark = placemarks[0];
NSDictionary *addressDictionary = placemark.addressDictionary;
NSString *address = [addressDictionary objectForKey:(NSString *) kABPersonAddressStreetKey];
address = address == nil ? @"": address;
NSString *state = [addressDictionary objectForKey:(NSString *) kABPersonAddressStateKey];
state = state == nil ? @"": state;
NSString *city = [addressDictionary objectForKey:(NSString *) kABPersonAddressCityKey];
city = city == nil ? @"": city;
NSLog(@"Place description: %@ \n%@ \n%@",state, address,city);
self.userAddress = [[NSString alloc] initWithFormat:@"%@", city];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"SetLiveShowAddress start");
int ret = SetLiveShowAddress(city, address);
if(ret == 0){
isSetAddress = TRUE;
[self.locationManager stopUpdatingLocation];
}
NSLog(@"SetLiveShowAddress end");
});
}
}];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"error: %@",error);
}
@end
简易的IOS位置定位服务的更多相关文章
- iOS设备定位服务开启判定
应用CLLocationManager 的两个方法 [CLLocationManagerlocationServicesEnabled] 判断设备是否开启定位功能 [CLLocationManager ...
- IOS定位服务的应用
IOS定位服务的应用 一.授权的申请与设置 二.定位服务相关方法 三.定位服务代理的相关方法 四.定位服务获取到的位置对象 五.航标定位得到的航标信息对象 IOS定位服务的应用 一.授权的申请与设置 ...
- iOS地图 -- 定位初使用
iOS的定位服务用到的框架是#import <CoreLocation/CoreLocation.h> 定位中用到的类是CLLocationManager 一.iOS8.0之前的定位 向用 ...
- iOS设备定位
一.iOS谈到定位 1.SignInSignOutViewController.h @interface SignInSignOutViewController : UIViewController& ...
- Push Notification总结系列之移动客户端定位服务
Push Notification系列概括: 1.Push Notification简介和证书说明及生成配置 2.Push Notification的iOS处理代码和Provider详解 3.Push ...
- Android网络定位服务定制简述
Android 添加高德或百度网络定位服务 Android的网络定位服务以第三方的APK方式提供服务,由于在国内Android原生自带的com.google.android.gms服务几乎处于不可用状 ...
- 【iOS】7.4 定位服务->2.1.2 定位 - 官方框架CoreLocation: CLLocationManager(位置管理器)
本文并非最终版本,如果想要关注更新或更正的内容请关注文集,联系方式详见文末,如有疏忽和遗漏,欢迎指正. 本文相关目录: ================== 所属文集:[iOS]07 设备工具 === ...
- iOS 硬件授权检测:定位服务、通讯录、日历、提醒事项、照片、蓝牙共享、麦克风、相机等(转)
转载自:http://www.cocoachina.com/ios/20151214/14502.html iOS系统版本的不断升级的前提,伴随着用户使用设备的安全性提升,iOS系统对于App需要使用 ...
- iOS开发拓展篇—CoreLocation定位服务
iOS开发拓展篇—CoreLocation定位服务 一.简单说明 1.CLLocationManager CLLocationManager的常用操作和属性 开始用户定位- (void)startUp ...
随机推荐
- java枚举与.net中的枚举区别
通过一段时间的项目实践,发现java中的枚举与.net中的枚举有很大的差别,初期造成了我对java中的枚举一些错误理解及部分有缺陷的应用,其实追其原因还是因为我会习惯性的认为java的枚举在作用以及定 ...
- 【转】给Windows + Apache 2.2 + PHP 5.3 安装PHP性能测试工具 xhprof
原文链接:http://blog.snsgou.com/post-816.html 1.下载XHProf 到这里 http://dev.freshsite.pl/php-extensions/xhpr ...
- C#的库存管理之旅的别样意义
我不知道大家对C#的一些基础知识掌握得怎么样了? 但无论怎么样,都应该静心下来去慢慢品味我的总结以及“库存管理”项目需用到的一些知识和技巧.你将会得到你料想不到的收获哦. 知识梳理: 数据类型:boo ...
- Xamarin安装和跳坑指南
安装Checklist 注意:本文只描述安装过程,由于组件的版本更新很快,为保证文章时效性,不提供下载链接,也尽可能不指明具体版本. 安装Visual Studio 2015进行默认安装,除非已经FQ ...
- 26款能够吸引用户的 iPhone App 界面设计
在这个移动互联网告诉的时代,众多的移动应用程序涌现出来.谁能抓住用户的注意力,谁就有可能成功.在下面这些移动 App 界面设计中,你可以看到不同创意类型的视觉效果,让你获得灵感. 您可能感兴趣的相关文 ...
- pywebsocket的搭建
Python可以搭建pywebsocket(Web服务器,python websocket),搭建pywebsocket必须要已经安装了python,点我查看python的下载与安装.在这篇Blog中 ...
- 每次点击按钮后,判断页面是否已经有该行,没有弹出repeater的一行,并给他赋一个这行附值,没有则跳出
protected void btnAdd_click(object sender, EventArgs e) { try { //记录第几次追加 pressCount++; typeString.A ...
- 使用js实现带有停顿效果的图片滚动(按钮控制)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Linux下EclipseCDT工程和TFS的持续集成CI实践
在Linux下使用TFS自动构建,需要自动执行连接tfs服务器的操作,命令行文件包TEE-CLC-10.1.0.2011121402.zip,下载地址:http://www.microsoft.com ...
- Android PopupWindow的使用和分析
Android PopupWindow的使用和分析 PopupWindow使用 PopupWindow这个类用来实现一个弹出框,可以使用任意布局的View作为其内容,这个弹出框是悬浮在当前activi ...