2018.3.10
demo下載地址 GitHub
demo是基于objective-c的純代碼實現(xiàn)编曼,已剝離xib豆巨,關(guān)于xib的本地化實現(xiàn),這里沒有掐场。
README
1.調(diào)用請求權(quán)限的方法之前往扔,需要先在Info.plist文件中配置2個KV,特別是第一個Key熊户,不可缺失.
Privacy - Location Always and When In Use Usage Description
Privacy - Location When In Use Usage Description
2.調(diào)用反地理編碼會產(chǎn)生網(wǎng)絡(luò)請求萍膛,需要網(wǎng)絡(luò)權(quán)限.
3.若請求權(quán)限時,系統(tǒng)定位服務(wù)未開啟嚷堡,則需要添加一下應(yīng)用進入前后臺的監(jiān)聽方法(退到后臺時添加回到前臺的方法卦羡,
回到前臺之后,移除監(jiān)聽對象)麦到,以在應(yīng)用回到前臺時判定發(fā)現(xiàn)定位服務(wù)已開啟的情況下重新調(diào)用請求權(quán)限的方法.
4.如果需要后臺持續(xù)定位绿饵,則需要先將Capabilities中的Background Modes中的Location Updates選項打開.
功能文件
可獲取經(jīng)緯度信息,以及利用(反地理編碼api+系統(tǒng)自動網(wǎng)絡(luò)請求)獲取詳細(xì)地理位置/城市信息瓶颠。
RFLocationHelper.h
RFLocationHelper.h.m
調(diào)用方式
1.基本調(diào)用拟赊,示例代碼:詳見demo中的 ViewController.m 文件。
以下補充(一點翻譯)
內(nèi)容轉(zhuǎn)載自網(wǎng)友整理粹淋, 原文鏈接
補充(一點翻譯)
屬性:
desiredAccuracy:定位精度吸祟,是一個枚舉類型
//kCLLocationAccuracyBest:最精確定位
//kCLLocationAccuracyNearestTenMeters:十米誤差范圍
//kCLLocationAccuracyHundredMeters:百米誤差范圍
//kCLLocationAccuracyKilometer:千米誤差范圍
//kCLLocationAccuracyThreeKilometers:三千米誤差范圍
方法:
//startUpdatingLocation:開始定位追蹤
//stopUpdatingLocation : 停止定位追蹤
//startUpdatingHeading:開始方向追蹤
//stopUpdatingHeading:停止方向追蹤
//startMonitoringForRegion : 開始對某個區(qū)域進行追蹤
//stopMonitoringForRegion : 停止對某區(qū)域進行追蹤
代理方法:
- (void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray *)locations; 位置發(fā)生改變后執(zhí)行
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading; 導(dǎo)航方向發(fā)生變化后執(zhí)行
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region瑟慈;進入某個區(qū)域
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;走出某個區(qū)域之后執(zhí)行
反地理編碼相關(guān):
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *loctaion = [locations firstObject];
NSLog(@"%f %f",loctaion.coordinate.latitude,loctaion.coordinate.longitude );
/*[geocoder reverseGeocodeLocation:loctaion completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark=[placemarks firstObject];
CLLocation *location=placemark.location;//位置
CLRegion *region=placemark.region;//區(qū)域
NSDictionary *addressDic= placemark.addressDictionary;//詳細(xì)地址信息字典,包含以下部分信息
// CLPlacemark *placemark = [placemarks firstObject];
// placemark.addressDictionary
NSString *name=placemark.name;//地名
NSString *thoroughfare=placemark.thoroughfare;//街道
NSString *subThoroughfare=placemark.subThoroughfare; //街道相關(guān)信息,例如門牌等
NSString *locality=placemark.locality; // 城市
NSString *subLocality=placemark.subLocality; // 城市相關(guān)信息屋匕,例如標(biāo)志性建筑
NSString *administrativeArea=placemark.administrativeArea; // 州
NSString *subAdministrativeArea=placemark.subAdministrativeArea; //其他行政區(qū)域信息
NSString *postalCode=placemark.postalCode; //郵編
NSString *ISOcountryCode=placemark.ISOcountryCode; //國家編碼
NSString *country=placemark.country; //國家
NSString *inlandWater=placemark.inlandWater; //水源葛碧、湖泊
NSString *ocean=placemark.ocean; // 海洋
NSArray *areasOfInterest=placemark.areasOfInterest; //關(guān)聯(lián)的或利益相關(guān)的地標(biāo)
}];*/
}