用途:在 Apple 平台以可移植方式表示地点信息,围绕 GeoToolbox 的 PlaceDescriptor 与 MapKit 集成,处理坐标、地址、通用名称及跨服务地点标识符。
主要能力:用 PlaceRepresentation.coordinate(CLLocationCoordinate2D) 或 .address(String) 构建地点,可同时传入多种表示;用 PlaceDescriptor(item: MKMapItem) 从现有地图项转换;通过 MKGeocodingRequest(addressString:) 做正向地理编码(地址转坐标),通过 MKReverseGeocodingRequest(location:) 做反向地理编码(坐标转地址),均以 try await request.mapItems 获取结果;用 SupportingPlaceRepresentation.serviceIdentifiers([String: String]) 附加 Apple Maps、Google Maps 等服务标识,并用 descriptor.serviceIdentifier(for:) 读取;可读取 descriptor.coordinate、descriptor.address、descriptor.commonName。
使用方式:使用 PlaceDescriptor 等需 import GeoToolbox;使用 MKGeocodingRequest、MKReverseGeocodingRequest、MKMapItem 需 import MapKit;使用 CLLocationCoordinate2D、CLLocation 需 import CoreLocation。反向地理编码需传入 CLLocation 而非原始坐标。
适用场景:需要以坐标、地址或名称表示地点,在 MKMapItem 与 PlaceDescriptor 间转换,做地址与坐标互转,或存储、传输多服务地点标识符以实现跨平台互操作。
限制:PlaceDescriptor、PlaceRepresentation、SupportingPlaceRepresentation、MKGeocodingRequest、MKReverseGeocodingRequest 及 PlaceDescriptor(item:) 最低要求 iOS 26 / macOS 26;MKMapItem 自 iOS 6 / macOS 10.9 起可用,CLLocationCoordinate2D 自 iOS 2 / macOS 10.6 起可用。地理编码可能因网络或服务失败抛错,结果可能为空,需做错误处理与空值检查;服务标识键为字符串,拼写错误会静默失败,建议用常量。其他细节暂未提供。