有时一些小的需求,其实只是需要得知当前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位置定位服务的更多相关文章

  1. iOS设备定位服务开启判定

    应用CLLocationManager 的两个方法 [CLLocationManagerlocationServicesEnabled] 判断设备是否开启定位功能 [CLLocationManager ...

  2. IOS定位服务的应用

    IOS定位服务的应用 一.授权的申请与设置 二.定位服务相关方法 三.定位服务代理的相关方法 四.定位服务获取到的位置对象 五.航标定位得到的航标信息对象 IOS定位服务的应用 一.授权的申请与设置 ...

  3. iOS地图 -- 定位初使用

    iOS的定位服务用到的框架是#import <CoreLocation/CoreLocation.h> 定位中用到的类是CLLocationManager 一.iOS8.0之前的定位 向用 ...

  4. iOS设备定位

    一.iOS谈到定位 1.SignInSignOutViewController.h @interface SignInSignOutViewController : UIViewController& ...

  5. Push Notification总结系列之移动客户端定位服务

    Push Notification系列概括: 1.Push Notification简介和证书说明及生成配置 2.Push Notification的iOS处理代码和Provider详解 3.Push ...

  6. Android网络定位服务定制简述

    Android 添加高德或百度网络定位服务 Android的网络定位服务以第三方的APK方式提供服务,由于在国内Android原生自带的com.google.android.gms服务几乎处于不可用状 ...

  7. 【iOS】7.4 定位服务->2.1.2 定位 - 官方框架CoreLocation: CLLocationManager(位置管理器)

    本文并非最终版本,如果想要关注更新或更正的内容请关注文集,联系方式详见文末,如有疏忽和遗漏,欢迎指正. 本文相关目录: ================== 所属文集:[iOS]07 设备工具 === ...

  8. iOS 硬件授权检测:定位服务、通讯录、日历、提醒事项、照片、蓝牙共享、麦克风、相机等(转)

    转载自:http://www.cocoachina.com/ios/20151214/14502.html iOS系统版本的不断升级的前提,伴随着用户使用设备的安全性提升,iOS系统对于App需要使用 ...

  9. iOS开发拓展篇—CoreLocation定位服务

    iOS开发拓展篇—CoreLocation定位服务 一.简单说明 1.CLLocationManager CLLocationManager的常用操作和属性 开始用户定位- (void)startUp ...

随机推荐

  1. Linux学习笔记17--Linux系统启动详解

    多数操作系统的启动流程: BIOS启动自检 ->MBR引导->执行引导程序GRUB->加载内核->执行init->runlevel   BIOS(Basic Input ...

  2. ImFire即时通讯系统构建(需求)

    ImFire需求 一期需求(近期) 1.新用户(账号)注册. 2.用户登入登出,支持pc端,移动端同时登录. 3.获取好友列表,包含好友的各种信息,状态. 4.根据用户id或用户名申请添加好友. 5. ...

  3. 从客户端(?)中检测到有潜在危险的 Request.Path 值 的解决方案

    public ActionResult A(string title) { return Redirect("B"+((String.IsNullOrEmpty(title))?& ...

  4. PHP代码审计中你不知道的牛叉技术点

    一.前言 php代码审计如字面意思,对php源代码进行审查,理解代码的逻辑,发现其中的安全漏洞.如审计代码中是否存在sql注入,则检查代码中sql语句到数据库的传输 和调用过程. 入门php代码审计实 ...

  5. SharePoint2013 错误

    英文错误信息: This operation can be performed only on a computer that is joined to a server farm by users ...

  6. Autodesk 产品开发培训开始报名-8月26~28-武汉– Revit, Vault, Autodesk Viewer, Navisworks

    为了帮助Autodesk中国地区的二次开发人员有机会系统地了解与学习Autodesk 在BIM解决方案中的旗舰产品 Revit以及Navisworks等产品的最新开发技术,并有机会与Autodesk ...

  7. NDK-JNI实战教程(二) JNI官方中文资料

    声明 设计概述 JNI接口函数和指针 加载和链接本地方法 解析本地方法名 本地方法的参数 引用Java对象 全局和局部引用 实现局部引用 访问Java对象 访问基本类型数组 访问域和方法 报告编程错误 ...

  8. 操作系统开发系列—13.d.多进程 ●

    进程此时不仅是在运行而已,它可以随时被中断,可以在中断处理程序完成之后被恢复.进程此时已经有了两种状态:运行和睡眠.我们已经具备了处理多个进程的能力,只需要让其中一个进程处在运行态,其余进程处在睡眠态 ...

  9. 使用eclipse开发android准备工作

    1.官网下载JDK  http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html    (注 ...

  10. Android 项目框架