相关疑难解决方法(0)

扩展CLPlacemark会导致EXC BAD ACCESS

虽然这里有一个类似的问题,但它没有提供答案,至少不是一般问题.

我的问题是:由于CoreLocation地理编码是速率有限的,我开发应用程序的(网络)服务提供了自己的后备地理编码服务,我想使用这个自定义地理编码服务,以防我达到Apple的速率限制.此外,我觉得避免使用此自定义REST API返回的结果的自定义数据类型是完全有意义的,因此希望使用返回的数据来生成CLPlacemarks.然而,该文档指出CLPlacemark如属性location, locality, administrativeArea等是read-only.因此,我创建了一个子类,CLPlacemark将所需的属性合成到我可以访问的私有变量上,即:

// interface: (.h)
@interface CustomPlacemark : CLPlacemark
- (nonnull id)initWithLocation: (nonnull CLLocation *)location
                      locality: (nullable NSString *)locality                       
            administrativeArea: (nullable NSString *)adminArea
                       country: (nullable NSString *)country;
@end

// implementation (.m)
@implementation CustomPlacemark
@synthesize location = _location;
@synthesize locality = _locality;
@synthesize country = _country;
@synthesize administrativeArea = _administrativeArea;

- (nonnull id)initWithLocation: (nonnull CLLocation *)location
                          locality: (nullable NSString *)locality
                administrativeArea: (nullable NSString *)adminArea …
Run Code Online (Sandbox Code Playgroud)

objective-c extend core-location ios clplacemark

2
推荐指数
1
解决办法
495
查看次数

标签 统计

clplacemark ×1

core-location ×1

extend ×1

ios ×1

objective-c ×1