有时一些小的需求,其实只是需要得知当前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. 附7 turbine

    一.作用 聚集同一个微服务的相同的commandKey.Threadpool.commandGroupKey数据进行聚合 二.配置 1.集群(cluster)(turbine聚集数据的粒度) turb ...

  2. [Android] 建立与使用Library

    [Android] 建立与使用Library 前言 使用Eclipse开发Android项目时,开发人员可以将可重用的程序代码,封装为Library来提供其他开发人员使用.本篇文章介绍如何将可重用的程 ...

  3. jQuery fullPage.js 全屏滚动

    fullPage 是一款不依赖任何 js 库的全屏滚动组件,支持垂直/水平滚动.CSS3 旋转/缩放动画,支持 IE5.5+,支持移动设备. 在线实例 垂直滚动 水平滚动 CSS3 动画1 CSS3 ...

  4. 免费 PSD 下载: 20个精美的登录和注册表单

    注册表单有许多不同的形状和尺寸,有的只是单个的输入框,有的则需要多个步骤.登录表单的设计将定义网站的性质,因此它应进行针对性的设计.下面的列表提供了20个醒目的登录和注册表单设计为您提供灵感. 您可能 ...

  5. [读码]HTML5像素文字爆炸重组

    [边读码,边学习,技术也好,思路也罢] [一款基于HTML5技术的文字像素爆炸重组动画特效,我们可以在输入框中指定任意文字,点击确定按钮后,就会将原先的文字爆炸散去,新的文字以像素点的形式组合起来,看 ...

  6. 使用 SQL的 for xml path来进行字符串拼接 (group by)

    参考: http://www.cnblogs.com/repository/archive/2011/01/18/1938418.html select convert(varchar(10),c.[ ...

  7. Troubleshooting FIM: (No Display Name) in FIM Portal

    from: http://social.technet.microsoft.com/wiki/contents/articles/12682.troubleshooting-fim-no-displa ...

  8. Android 短信的还原

    上篇文章讲到<Android 短信的备份>,本文主要实现Android 短信的还原,即是将一条 布局文件: <RelativeLayout xmlns:android="h ...

  9. 【代码笔记】iOS-判断有无网络

    一,工程图. 二,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController : UIVi ...

  10. 【代码笔记】iOS-仿安卓,本页出现多个选择项

    一,效果图. 二,代码. //点击任何处,弹出提示选项 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UIAlert ...