Skip to content

usePointGeocoder ^0.0.39

由坐标点解析地址信息

ts
import { usePointGeocoder } from 'vue3-baidu-map-gl'

单个坐标点解析

使用坐标点对象作为 get 方法参数解析单个坐标点

TIP

在 Ts 中使用批量解析坐标点时,使用泛型PointGeocoderResult内部可推断result为可推断为PointGeocoderResult,从而避免读取值时 ts 的报错。

ts
import { usePointGeocoder, PointGeocoderResult } from 'vue3-baidu-map-gl'
const { result } = usePointGeocoder<PointGeocoderResult>()

批量解析坐标点

使用坐标点对象数组作为 get 方法参数批量解析坐标点

TIP

在 Ts 中使用批量解析坐标点时,使用泛型PointGeocoderResult[]内部可推断result为可推断为PointGeocoderResult[],从而避免遍历时 ts 的报错。

ts
import { usePointGeocoder, PointGeocoderResult } from 'vue3-baidu-map-gl'
const { result } = usePointGeocoder<PointGeocoderResult[]>()

用法

ts
const { get, result, isLoading, isEmpty } = usePointGeocoder(options, cal)

TIP

该 hooks 依赖于 BMapGL ,所以需要在 Map 组件初始化完毕调用 get 方法后数据才可用

参数

参数描述类型默认值
options解析配置UsePointGeocoderOptions-
cal定位成功后的回调函数(result: Ref<PointGeocoderResult | PointGeocoderResult[] | null>) => void-

UsePointGeocoderOptions

属性描述类型
poiRadius附近 POI 所处于的最大半径,默认为 100 米number
numPois返回的 POI 点个数,默认为 10 个。取值范围number

返回值

返回值描述类型
isLoading是否在获取中boolean
isEmpty是否有解析结果boolean
result坐标点解析结果Ref<PointGeocoderResult | PointGeocoderResult[] | null>
get获取坐标点信息方法,需要在Map组件initd事件触发后才可调用(point: Point | Point[]) => void]

Point

ts
type Point = { lng: number; lat: number }

PointGeocoderResult

属性描述类型
point坐标点boolean
string地址描述string
AddressComponent结构化的地址描述AddressComponent
surroundingPois附近的 POI 点LocalResultPoi
business商圈字段,代表此点所属的商圈string
AddressComponent
属性描述类型
streetNumber门牌号码string
street街道名称string
district区县名称string
city城市名称string
province省份名称string
LocalResultPoi
属性描述类型
title结果的名称标题string
point该结果所在的地理位置point
url在百度地图中展示该结果点的详情信息链接string
address地址(根据数据部分提供)。注:当结果点类型为公交站或地铁站时,地址信息为经过该站点的所有车次string
city所在城市string
phoneNumber电话,根据数据部分提供string
postcode邮政编码,根据数据部分提供string
type类型,根据数据部分提供PoiType
uid地点 idstring
tagsPOI 的标签,如商务大厦、餐馆等。string[]
PoiType
描述
0一般位置点
1公交车站位置点
3地铁车站位置点

TS 类型定义参考

ts
import { Ref } from 'vue'
import { Point } from 'vue3-baidu-map-gl'
export interface PointGeocoderResult {
  /**
   * 坐标点
   */
  point: Point
  /**
   * 地址描述
   */
  address: string
  /**
   * 结构化的地址描述
   */
  addressComponents: {
    city: string
    district: string
    province: string
    street: string
    streetNumber: string
  }
  /**
   * 附近的POI点
   */
  surroundingPois: Array<BMapGL.LocalResultPoi>
  /**
   * 商圈字段,代表此点所属的商圈
   */
  business: string
}
/**
 * 由地址解析坐标点
 */
export declare function usePointGeocoder<
  T extends PointGeocoderResult | PointGeocoderResult[] = PointGeocoderResult | PointGeocoderResult[]
>(
  options?: BMapGL.LocationOptions | null,
  cal?: (point: Ref<T>) => void
): {
  get: (point: T extends PointGeocoderResult ? Point : Point[]) => void
  result: Ref<T | null | undefined>
  isLoading: Ref<boolean>
  isEmpty: Ref<boolean>
}

Released under the MIT License.