FWLocationManager

@interface FWLocationManager : NSObject

位置服务

Note

注意:Info.plist需要添加NSLocationWhenInUseUsageDescription项 如果请求Always定位,还需添加NSLocationAlwaysUsageDescription项和NSLocationAlwaysAndWhenInUseUsageDescription项 iOS11可通过showsBackgroundLocationIndicator配置是否显示后台定位指示器
  • 单例模式

    Declaration

    Objective-C

    @property (class, nonatomic, readonly) FWLocationManager *_Nonnull sharedInstance;
  • 是否启用Always定位,默认NO,请求WhenInUse定位

    Declaration

    Objective-C

    @property (nonatomic) BOOL alwaysLocation;
  • 是否启用后台定位,默认NO。如果需要后台定位,设为YES即可

    Declaration

    Objective-C

    @property (nonatomic) BOOL backgroundLocation;
  • 是否启用方向监听,默认NO。如果设备不支持方向,则不能启用

    Declaration

    Objective-C

    @property (nonatomic) BOOL headingEnabled;
  • 是否发送通知,默认NO。如果需要通知,设为YES即可

    Declaration

    Objective-C

    @property (nonatomic) BOOL notificationEnabled;
  • 定位完成是否立即stop,默认NO。如果为YES,只会回调一次

    Declaration

    Objective-C

    @property (nonatomic) BOOL stopWhenCompleted;
  • 位置管理对象

    Declaration

    Objective-C

    @property (nonatomic, readonly) CLLocationManager *_Nonnull locationManager;
  • 当前位置,中途定位失败时不会重置

    Declaration

    Objective-C

    @property (nonatomic, readonly, nullable) CLLocation *location;
  • 当前方向,headingEnabled启用后生效

    Declaration

    Objective-C

    @property (nonatomic, readonly, nullable) CLHeading *heading;
  • 当前错误,表示最近一次定位回调状态

    Declaration

    Objective-C

    @property (nonatomic, readonly, nullable) NSError *error;
  • 定位改变block方式回调,可通过error判断是否定位成功

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) void (^) (FWLocationManager *_Nonnull __strong) locationChanged;
  • 坐标转“纬度,经度"字符串

    Declaration

    Objective-C

    + (nonnull NSString *)locationString:(CLLocationCoordinate2D)coordinate;
  • “纬度,经度"字符串转坐标

    Declaration

    Objective-C

    + (CLLocationCoordinate2D)locationCoordinate:(nonnull NSString *)string;
  • 开始更新位置

    Declaration

    Objective-C

    - (void)startUpdateLocation;
  • 停止更新位置

    Declaration

    Objective-C

    - (void)stopUpdateLocation;