美文网首页
SYCLLocation定位与反编码

SYCLLocation定位与反编码

作者: 番薯大佬 | 来源:发表于2017-10-17 14:45 被阅读5次

SYCLLocation使用系统地图进行定位及反编码(二次封装类,便于开发)。

效果图1效果图1
效果图2效果图2

代码示例

// 导入封装类头文件
#import "SYCLLocation.h"
// 封装方法 开启定位
[[SYCLLocation shareLocation] locationStart:^(CLLocation *location, CLPlacemark *placemark) {
    NSString *name = placemark.name;
    NSString *thoroughfare = placemark.thoroughfare;
    NSString *subThoroughfare = placemark.subThoroughfare;
    NSString *subLocality = placemark.subLocality;
    NSString *administrativeArea = placemark.administrativeArea;
    NSString *subAdministrativeArea = placemark.subAdministrativeArea;
    NSString *postalCode = placemark.postalCode;
    NSString *ISOcountryCode = placemark.ISOcountryCode;
    NSString *country = placemark.country;
    NSString *inlandWater = placemark.inlandWater;
    NSString *ocean = placemark.ocean;
    NSArray *areasOfInterest = placemark.areasOfInterest;
    // 获取城市
    NSString *city = placemark.locality;
    if (!city)
    {
        // 四大直辖市的城市信息无法通过locality获得,只能通过获取省份的方法来获得(如果city为空,则可知为直辖市)
        city = placemark.administrativeArea;
    }

    NSMutableString *text = [[NSMutableString alloc] initWithFormat:@"纬度=%f,经度=%f\n", location.coordinate.latitude, location.coordinate.longitude];
    [text appendFormat:@"city=%@\n", city];
    [text appendFormat:@"name=%@\n", name];
    [text appendFormat:@"thoroughfare=%@\n", thoroughfare];
    [text appendFormat:@"subThoroughfare=%@\n", subThoroughfare];
    [text appendFormat:@"subLocality=%@\n", subLocality];
    [text appendFormat:@"administrativeArea=%@\n", administrativeArea];
    [text appendFormat:@"subAdministrativeArea=%@\n", subAdministrativeArea];
    [text appendFormat:@"postalCode=%@\n", postalCode];
    [text appendFormat:@"ISOcountryCode=%@\n", ISOcountryCode];
    [text appendFormat:@"country=%@\n", country];
    [text appendFormat:@"inlandWater=%@\n", inlandWater];
    [text appendFormat:@"inlandWater=%@\n", inlandWater];
    [text appendFormat:@"ocean=%@\n", ocean];
    [text appendFormat:@"areasOfInterest=%@\n", areasOfInterest];
    NSLog(@"%@", text);
} faile:^(NSError *error) {
    if (error)
    {
        if (([error code] == kCLErrorDenied))
        {
            NSLog(@"定位未打开,请打开定位服务");
        }
        else
        {
            NSLog(@"An error occurred = %@", error);
        }
    }
    else
    {
        NSLog(@"No results were returned.");
    }
}];
// 封装方法 结束定位
[[SYCLLocation shareLocation] locationStop];

注意事项

  • 添加CoreLocation.framework
  • 导入头文件
    • /#import <CoreLocation/CoreLocation.h>
    • /#import <CoreLocation/CLLocationManager.h>
  • plist文件中设置定位的私有属性
    • NSLocationAlwaysUsageDescription 设置为 YES
    • NSLocationWhenInUseUsageDescription 设置为 YES
    • NSLocationUsageDescription 设置提示语,如:想知道你在哪里?
plist文件配置示意图plist文件配置示意图

相关文章

  • SYCLLocation定位与反编码

    SYCLLocation使用系统地图进行定位及反编码(二次封装类,便于开发)。 代码示例 注意事项添加CoreLo...

  • IOS系统定位

    一、介绍 1、定位使用CoreLocation框架 2、功能 (1)、基础定位 (2)、地理编码 与反编...

  • 高德地图问题

    1:定位的时候获取用户的省市区位置,通过反地理编码 地理编码与反地理编码 地理编码:根据地址获得相应的经纬度以及详...

  • 学习笔记 - 地图

    1.iOS系统定位 2.地理编码与反编码 3.MapView 4.添加大头针

  • iOS--定位——编码与反编码

    一、基本介绍 1、定位,基于GPS 定位是一个很常用的功能,打开地图软件后如果用户允许软件定位的话,软件便会自动锁...

  • 地图和定位(三)

    一、地理编码和反地理编码 地理编码:把地址转为经纬度反地理编码:把经纬度转为地址 二、获取当前城市名称(定位+反地...

  • MapView演练

    结合MapView与LBS相关知识点:定位、地理编码/反地理编码、地图覆盖物、导航写了一个小的Demo 并且在导航...

  • iOS开发之定位

    一、介绍 1、定位使用CoreLocation框架2、主要功能(1)基础定位(2)地理编码反编码3、IOS8 IO...

  • iOS开发之地图-定位/编码与反编码

    #前言 学习地图,我们必须要接触两个框架: Core Location,主要包含定位、地理编码、反编码功能 Map...

  • coreLocation

    用途 : 地理定位,地理编码与反编码(将经纬度与地理位置的相互转化),区域监测(在用户出现在区域范围内的时候调用监...

网友评论

      本文标题:SYCLLocation定位与反编码

      本文链接:https://www.haomeiwen.com/subject/bmjduxtx.html