有时一些小的需求,其实只是需要得知当前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. IO碰到的问题

    1.流关了,并不代表流对象为空 可是java并没提供查看流是否关闭的方法 不过如果流已经关闭了以后,再对流进行操作的话,会抛出IOException:Stream closed异常 可以根据这个异常来 ...

  2. 经典网页设计:20个与众不同的国外 HTML5 网站

    大家都都知道, HTML5 具备所有最新的技术和功能,帮助我们创造平滑过渡,花式图像滑块和动画.如果你正在考虑使用HTML5 来设计自己的网站,那么这个集合能够帮助你. 在过去的10年里,网页设计师使 ...

  3. 根据网址把图片下载到服务器C#代码

    根据网址把图片下载到服务器C#代码 ASPX页面代码: <%@ Page Language="C#" AutoEventWireup="true" Cod ...

  4. canvas画布在主流浏览器中的尺寸限制

    通过测试发现,canvas在不同浏览器下面有不同的最大尺寸限制. 大家都知道,canvas有自身的width,height属性来控制尺寸,用css的width,height,控制显示的大小.可以理解为 ...

  5. 向ArcGIS的ToolBarControl中添加任意的windows控件的方法

    概要:在使用ArcEngine开发中,给ToolbarControl添加按钮形式的命令项相信大家都很熟悉了,因为网上的例子很多.但这种使用click调用功能的方式只能满足大部分用户在体验方面的需求,除 ...

  6. 定时从多个Excel导入数据到SQL数据库

    Scheduling Data Imports in SQL Server Importing data into a SQL Server database isn't really that tr ...

  7. Android ThreadUtil 线程公共类,判断是否在主线程/ 子线程执行 相关操作

    前言:通常,我们写的公共的模块给别人用,但是这个模块又必须在特定的线程中执行. 比如,一个加载网络图片的的方法,需要在子线程中执行. /** * 加载网络图片 */ private void load ...

  8. Android 使用SoundPool播放音效

    在Android开发中我们经常使用MediaPlayer来播放音频文件,但是MediaPlayer存在一些不足,例如:资源占用量较高.延迟时间较长.不支持多个音频同时播放等.这些缺点决定了MediaP ...

  9. 你真的了解UIView吗?

    一:首先查看一下关于UIView的定义 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIView : UIResponder <NSCoding, UIAppe ...

  10. Android中各种Drawable总结

    在Android中,Drawable使用广泛,但是种类也多,基于<Android开发艺术探索>中对Drawable的讲解,总结了如下表格.