gpt4 book ai didi

ios - 如何从 CLPlaceMark 获取 map_region

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:12:23 25 4
gpt4 key购买 nike

我必须从 CLPlaceMark 中取出 map_region 和类型,但在 CLPlaceMark 类中找不到可以提供 map_region 值的属性。

 {
placeData = {
component = (
{
"cache_control" = UNCACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
type = "COMPONENT_TYPE_HOURS";
"values_available" = 0;
},
{
"cache_control" = UNCACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
type = "COMPONENT_TYPE_RATING";
"values_available" = 0;
},
{
"cache_control" = UNCACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
type = "COMPONENT_TYPE_FLYOVER";
"values_available" = 0;
},
{
"cache_control" = UNCACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
type = "COMPONENT_TYPE_BOUNDS";
value = (
{
bounds = {
"map_region" = {
eastLng = "-73.832921";
northLat = "40.739434";
southLat = "40.550334";
westLng = "-74.056687";
};
};
}
);
"values_available" = 1;
},
{
"cache_control" = UNCACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
type = "COMPONENT_TYPE_ROAD_ACCESS_INFO";
"values_available" = 0;
},
{
"cache_control" = UNCACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
type = "COMPONENT_TYPE_PLACE_INFO";
value = (
{
"place_info" = {
center = {
lat = "40.692529";
lng = "-73.990996";
};
timezone = {
identifier = "America/New_York";
};
};
}
);
"values_available" = 1;
},
{
"cache_control" = UNCACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
type = "COMPONENT_TYPE_ENTITY";
value = (
{
entity = {
"is_disputed" = 0;
name = (
{
locale = "en_US";
"string_value" = Brooklyn;
}
);
type = "SUB_LOCALITY";
};
}
);
"values_available" = 1;
},
{
"cache_control" = UNCACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
type = "COMPONENT_TYPE_ADDRESS";
value = (
{
address = {
"localized_address" = (
{
address = {
formattedAddressLine = (
"Brooklyn, NY",
"United States"
);
structuredAddress = {
administrativeArea = "New York";
administrativeAreaCode = NY;
areaOfInterest = (
"Long Island"
);
country = "United States";
countryCode = US;
geoId = (
);
locality = Brooklyn;
subAdministrativeArea = Kings;
};
};
locale = "en_US";
}
);
};
}
);
"values_available" = 1;
},
{
"cache_control" = UNCACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
type = "COMPONENT_TYPE_AMENITIES";
"values_available" = 0;
},
{
"cache_control" = UNCACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
type = "COMPONENT_TYPE_STYLE_ATTRIBUTES";
"values_available" = 0;
},
{
"cache_control" = UNCACHEABLE;
"start_index" = 0;
status = "STATUS_SUCCESS";
type = "COMPONENT_TYPE_BUSINESS_CLAIM";
"values_available" = 0;
}
);
"result_provider_id" = 6489;
status = "STATUS_SUCCESS";
};
}

有什么方法可以从 CLPlaceMark 类中读取值吗?

最佳答案

CLPlacemark 没有任何属性来访问它的底层存储数据(私有(private) GEOMapItemStorage)。然而,有一种方法可以访问这些数据,尽管它是一种 hacky 方法,您应该非常小心地使用它。

当您尝试打印 CLPlacemark 实例控制台日志时,还会打印 GEOMapItemStorage,因此理论上您可以访问此字符串并将其转换为字典。棘手的部分是它是一个原始字符串,您必须对其进行一些处理。我正在向 CLPlacemark 发布一个扩展,它应该完成这项工作并返回 [String: AnyObject]?

extension CLPlacemark {

enum GeoMapItemStorageError: ErrorType {
case InvalidFormat
case DataEncoding
case Serialization(underlaying: ErrorType)
}

func extractGeoMapItemStorage() throws -> [String: AnyObject]? {

let description = self.description as NSString
let indexOfBracket = description.rangeOfString("{", options: NSStringCompareOptions.init(rawValue: 0))

guard indexOfBracket.location != NSNotFound else {
throw GeoMapItemStorageError.InvalidFormat
}

let dictString = description.substringFromIndex(indexOfBracket.location)

guard let dictStringData = dictString.dataUsingEncoding(NSUTF8StringEncoding) else {
throw GeoMapItemStorageError.DataEncoding
}

do {
return try NSPropertyListSerialization.propertyListWithData(
dictStringData,
options: NSPropertyListReadOptions.Immutable,
format: nil
) as? [String: AnyObject]
}
catch (let error){
throw GeoMapItemStorageError.Serialization(underlaying: error)
}

}
}

关于ios - 如何从 CLPlaceMark 获取 map_region,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32732971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com