Location
API 提供方法来访问设备的当前位置,将坐标反向地理编码为地址信息,并使用 iOS 内置地图选择位置。此 API 支持设置位置精度并在应用中处理地理位置信息。
Location
Location
类使您能够与设备的位置服务交互。使用此 API 可获取当前位置、反向地理编码坐标,或允许用户在地图上选择位置。
Location.setAccuracy(accuracy: LocationAccuracy): Promise<void>
设置应用请求的位置数据的精度级别。
accuracy
: 所需的精度级别,例如 high
或 low
。(具体值请参考 LocationAccuracy
文档。)Location.requestCurrent(): Promise<LocationInfo | null>
请求一次性获取用户的当前位置。
LocationInfo
对象;如果无法获取位置,则返回 null
。Location.pickFromMap(): Promise<LocationInfo | null>
展示 iOS 内置地图界面,让用户选择一个位置。
LocationInfo
对象;如果用户取消选择,则返回 null
。Location.reverseGeocode(options: { latitude: number; longitude: number; locale?: string }): Promise<LocationPlacemark[] | null>
对指定坐标提交反向地理编码请求以检索地址信息。
latitude: number
: 纬度(以度为单位)。longitude: number
: 经度(以度为单位)。locale?: string
: 返回地址信息的语言环境。指定 null
以使用用户的默认语言环境。LocationPlacemark
对象数组;如果反向地理编码失败,则返回 null
。LocationInfo
表示从设备或用户选择中获取的位置信息。
latitude: number
: 位置的纬度。longitude: number
: 位置的经度。altitude?: number
: 位置的海拔(如果可用)。horizontalAccuracy?: number
: 位置数据的水平精度。verticalAccuracy?: number
: 位置数据的垂直精度。timestamp: Date
: 获取位置信息的时间戳。LocationPlacemark
表示特定位置的地址详细信息。
name?: string
: 地点名称(例如地标名称)。thoroughfare?: string
: 街道名称。subThoroughfare?: string
: 街道号码。locality?: string
: 城市名称。subLocality?: string
: 区域或街区名称。administrativeArea?: string
: 州或省份。subAdministrativeArea?: string
: 县或其他次级行政区划。postalCode?: string
: 邮政编码或 ZIP 码。country?: string
: 国家名称。isoCountryCode?: string
: ISO 国家代码。LocationAccuracy
定义位置数据的所需精度级别。
"high"
,"medium"
,"low"
。Location
API 之前,请确保应用在系统设置中启用了适当的位置权限。null
值,因为由于连接问题或用户权限限制,服务可能会失败。