【小程序开发】位置 API 集合(二)

ty.map.openGeofenceMap

打开地理围栏地图页面,获取地理围栏信息(新建或者编辑地理围栏)

权限: [scope.location]

需引入MapKit,且在>=3.0.1版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
geoTitle string 地理围栏名称
longitude number 经度
latitude number 纬度
radius number 半径
geofenceId string id
type number 半径 0:进度地理围栏 1:离开地理围栏
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

函数定义示例

复制代码
/**
 * 打开地理围栏地图页面,获取地理围栏信息(新建或者编辑地理围栏)
 *权限: [scope.location]
 */
export function openGeofenceMap(params?: {
  /** 地理围栏名称 */
  geoTitle?: string;
  /** 经度 */
  longitude?: number;
  /** 纬度 */
  latitude?: number;
  /** 半径 */
  radius?: number;
  /** id */
  geofenceId?: string;
  /**
   * 半径
   * 0:进度地理围栏
   * 1:离开地理围栏
   */
  type?: number;
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  complete?: () => void;
  /** 接口调用成功的回调函数 */
  success?: (params: null) => void;
  /** 接口调用失败的回调函数 */
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

👉 立即开发

ty.map.openMapAppLocation

使用三方地图查看位置

需引入MapKit,且在>=2.1.1版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
latitude number 纬度,范围为 -90~90,负数表示南纬
longitude number 经度,范围为 -180~180,负数表示西经
name string 位置名
address string 地址的详细说明
mapType string 地图类型,目前支持:BMK:百度地图 MA:高德地图 TENCENT:腾讯地图 Google:Google 地图
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

函数定义示例

复制代码
/**
 * 使用三方地图查看位置
 */
export function openMapAppLocation(params: {
  /** 纬度,范围为 -90~90,负数表示南纬 */
  latitude: number;
  /** 经度,范围为 -180~180,负数表示西经 */
  longitude: number;
  /** 位置名 */
  name: string;
  /** 地址的详细说明 */
  address: string;
  /** 地图类型,目前支持:BMK:百度地图 MA:高德地图 TENCENT:腾讯地图 Google:Google地图 */
  mapType: string;
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  complete?: () => void;
  /** 接口调用成功的回调函数 */
  success?: (params: null) => void;
  /** 接口调用失败的回调函数 */
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.map.registerGeofence

注册地理围栏

权限: [scope.location]

需引入MapKit,且在>=3.0.1版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
geoTitle string 地理围栏名称
longitude number 经度
latitude number 纬度
radius number 半径
geofenceId string id
type number 半径 0:进度地理围栏 1:离开地理围栏
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

函数定义示例

复制代码
/**
 * 注册地理围栏
 *权限: [scope.location]
 */
export function registerGeofence(params?: {
  /** 地理围栏名称 */
  geoTitle?: string;
  /** 经度 */
  longitude?: number;
  /** 纬度 */
  latitude?: number;
  /** 半径 */
  radius?: number;
  /** id */
  geofenceId?: string;
  /**
   * 半径
   * 0:进度地理围栏
   * 1:离开地理围栏
   */
  type?: number;
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  complete?: () => void;
  /** 接口调用成功的回调函数 */
  success?: (params: null) => void;
  /** 接口调用失败的回调函数 */
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.map.unregisterGeofence

取消地理围栏

权限: [scope.location]

需引入MapKit,且在>=3.0.1版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
geoTitle string 地理围栏名称
longitude number 经度
latitude number 纬度
radius number 半径
geofenceId string id
type number 半径 0:进度地理围栏 1:离开地理围栏
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

函数定义示例

复制代码
/**
 * 取消地理围栏
 *权限: [scope.location]
 */
export function unregisterGeofence(params?: {
  /** 地理围栏名称 */
  geoTitle?: string;
  /** 经度 */
  longitude?: number;
  /** 纬度 */
  latitude?: number;
  /** 半径 */
  radius?: number;
  /** id */
  geofenceId?: string;
  /**
   * 半径
   * 0:进度地理围栏
   * 1:离开地理围栏
   */
  type?: number;
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  complete?: () => void;
  /** 接口调用成功的回调函数 */
  success?: (params: null) => void;
  /** 接口调用失败的回调函数 */
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.map.transformLocation

根据经纬度获取地址

需引入MapKit,且在>=3.2.2版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
type string wgs84 返回 gps 坐标,gcj02 返回可用于 openLocation 的坐标
latitude number 纬度,范围为 -90~90,负数表示南纬
longitude number 经度,范围为 -180~180,负数表示西经
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

object.success回调参数

参数

Object res

属性 类型 说明
latitude number 纬度,范围为 -90~90,负数表示南纬
longitude number 经度,范围为 -180~180,负数表示西经
cityName string 城市名称street
streetName string 街道名称
address string 位置名称
countryCode string 国家码
postalCode string 邮编
countryName string 国家名
province string 省名
district string 区名, 次级区域名

object.fail回调参数

参数

Object res

属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {errorMsg: string, errorCode: string }

函数定义示例

复制代码
/**
 * 根据经纬度获取地址
 */
export function transformLocation(params: {
  /** wgs84 返回 gps 坐标,gcj02 返回可用于 openLocation 的坐标 */
  type: string
  /** 纬度,范围为 -90~90,负数表示南纬 */
  latitude: number
  /** 经度,范围为 -180~180,负数表示西经 */
  longitude: number
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  complete?: () => void
  /** 接口调用成功的回调函数 */
  success?: (params: {
    /** 纬度,范围为 -90~90,负数表示南纬 */
    latitude: number
    /** 经度,范围为 -180~180,负数表示西经 */
    longitude: number
    /** 城市名称street */
    cityName: string
    /** 街道名称 */
    streetName: string
    /** 位置名称 */
    address: string
    /** 国家码 */
    countryCode: string
    /** 邮编 */
    postalCode: string
    /** 国家名 */
    countryName: string
    /** 省名 */
    province: string
    /** 区名, 次级区域名 */
    district: string
  }) => void
  /** 接口调用失败的回调函数 */
  fail?: (params: {
    errorMsg: string
    errorCode: string | number
    innerError: {
      errorCode: string | number
      errorMsg: string
    }
  }) => void
}): void

👉 立即开发

相关推荐
京东零售技术5 分钟前
京东小程序JS API仓颉改造实践
前端
nbsaas-boot11 分钟前
[特殊字符] 分享裂变新姿势:用 UniApp + Vue3 玩转小程序页面分享跳转!
小程序·uniapp·notepad++
奋飛14 分钟前
TypeScript系列:第六篇 - 编写高质量的TS类型
javascript·typescript·ts·declare·.d.ts
老A技术联盟14 分钟前
从小白入门,基于Cursor开发一个前端小程序之Cursor 编程实践与案例分析
前端·小程序
you458017 分钟前
小程序学习笔记:使用 MobX 实现全局数据共享,实例创建、计算属性与 Actions 方法
笔记·学习·小程序
风铃喵游18 分钟前
构建引擎: 打造小程序编译器
前端·小程序·架构
sunbyte23 分钟前
50天50个小项目 (Vue3 + Tailwindcss V4) ✨ | ThemeClock(主题时钟)
前端·javascript·css·vue.js·前端框架·tailwindcss
小飞悟31 分钟前
🎯 什么是模块化?CommonJS 和 ES6 Modules 到底有什么区别?小白也能看懂
前端·javascript·设计
浏览器API调用工程师_Taylor32 分钟前
AOP魔法:一招实现登录弹窗的全局拦截与动态处理
前端·javascript·vue.js
FogLetter33 分钟前
初识图片懒加载:让网页像"懒人"一样聪明加载
前端·javascript