title: Taro.openLocation(option)

sidebar_label: openLocation

使用微信内置地图查看位置

支持情况:openLocation - 图1 openLocation - 图2 openLocation - 图3 openLocation - 图4

参考文档

类型

  1. (option: Option) => Promise<TaroGeneral.CallbackResult>

参数

参数 类型
option Option

Option

参数 类型 必填 说明
latitude number 纬度,范围为-90~90,负数表示南纬。使用 gcj02 国测局坐标系
longitude number 经度,范围为-180~180,负数表示西经。使用 gcj02 国测局坐标系
address string 地址的详细说明
complete (res: TaroGeneral.CallbackResult) => void 接口调用结束的回调函数(调用成功、失败都会执行)
fail (res: TaroGeneral.CallbackResult) => void 接口调用失败的回调函数
name string 位置名
scale number 缩放比例,范围5~18
success (res: TaroGeneral.CallbackResult) => void 接口调用成功的回调函数

示例代码

  1. Taro.getLocation({
  2. type: 'gcj02', //返回可以用于 Taro.openLocation的经纬度
  3. success: function (res) {
  4. const latitude = res.latitude
  5. const longitude = res.longitude
  6. Taro.openLocation({
  7. latitude,
  8. longitude,
  9. scale: 18
  10. })
  11. }
  12. })