Latest 1.1.0
Homepage https://github.com/potato512/SYCLLocation
License MIT
Platforms ios 8.0, requires ARC
Frameworks CoreLocation
Authors

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

效果图

locationImage01.gif

locationImage02.gif

使用示例

导入封装类头文件

#import "SYCLLocation.h"

判断定位是否可用

BOOL isValid = [[SYCLLocation shareLocation] isEnabledLocation];

开启定位

[[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,经度=%fn", location.coordinate.latitude, location.coordinate.longitude];
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    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];

注意事项

  • 1、添加CoreLocation.framework
  • 2、导入头文件
    • import <CoreLocation/CoreLocation.h>

    • import <CoreLocation/CLLocationManager.h>

  • 3、plist文件中设置定位的私有属性
    • NSLocationAlwaysUsageDescription 设置为 YES
    • NSLocationWhenInUseUsageDescription 设置为 YES
    • NSLocationUsageDescription 设置提示语,如:想知道你在哪里?

plist文件配置示意图

locationImage00.png

修改说明

  • 20180807

    • 版本号:1.1.0
    • 修改完善
  • 20171017
    • 版本号:1.0.1
    • 说明文档完善
    • 添加效果示意图
    • 源码与示例分离

Latest podspec

{
    "name": "SYCLLocation",
    "version": "1.1.0",
    "summary": "SYCLLocation used to find your position as easy as possible.",
    "homepage": "https://github.com/potato512/SYCLLocation",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "herman": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/potato512/SYCLLocation.git",
        "tag": "1.1.0"
    },
    "source_files": "SYCLLocation/*.{h,m}",
    "frameworks": "CoreLocation",
    "requires_arc": true
}

Pin It on Pinterest

Share This