微信小程序开发文档 第23页

微信小程序API 监听实时地理位置

wx.onLocationChange(function callback) 基础库 2.8.1 开始支持,低版本需做兼容处理。 监听实时地理位置变化事件,需结合 wx.startLocationUpdateBackground、wx.startLocationUpdate使用。 参数 function callback 实时地理位置变化事件的回调函数 参数 Object res 属性 类型 说明 最低版本 latitude number 纬度,范围为 -90~90,负数表示南纬 longitude number 经度,范围为 -180~180,负数表示西经 speed number 速度,单位 m/s accuracy number 位置的精确度 altitude number 高度,单位 m 1.2.0 verticalAccuracy number 垂直精度,单位 m(Android 无法获取,返回 0) 1.2.0 horizontalAccuracy number 水平精度,单位 m 1.2.0 示例代码 const _locationChangeFn = function(res) { console.log('location change', res) } wx.onLocationChange(_locationChangeFn) wx.offLocationChange(_locationChangeFn) wx.offLocationChange(function callback) 基础库 2.8.1 开始支持,低版本需做兼容处理。 取消监听实时地理位置变化事件 参数 function callback 实时地理位置变化事件的回调函数

微信小程序API 地图组件控制

wx.createMapContext(mapId) 创建并返回 map 上下文 mapContext 对象。在自定义组件下,第二个参数传入组件实例this,以操作组件内 <map/> 组件 mapContext mapContext通过 mapId 跟一个<map/>组件绑定,通过它可以操作对应的<map/>组件。 mapContext 对象的方法列表 方法 参数 说明 最低版本 getCenterLocation OBJECT 获取当前地图中心的经纬度,返回的是 gcj02 坐标系,可以用于 wx.openLocation   moveToLocation 无 将地图中心移动到当前定位点,需要配合map组件的show-location使用   translateMarker OBJECT 平移marker,带动画 1.2.0 includePoints OBJECT 缩放视野展示所有经纬度 1.2.0 getRegion OBJECT 获取当前地图的视野范围 1.4.0 getScale OBJECT 获取当前地图的缩放级别 1.4.0 getCenterLocation 的 OBJECT 参数列表 参数 类型 必填 说明 success Function 否 接口调用成功的回调函数 ,res = { longitude: “经度”, latitude: “纬度”} fail Function 否 接口调用失败的回调函数 complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行) translateMarker 的 OBJECT 参数列表 参数 类型 必填 说明 markerId Number 是 指定marker destination Object 是 指定marker移动到的目标点 autoRotate Boolean 是 移动过程中是否自动旋转marker rotate Number 是 marker的旋转角度 duration Number 否 动画持续时长,默认值1000ms,平移与旋转分别计算 animationEnd Function 否 动画结束回调函数 fail Function 否 接口调用失败的回调函数 includePoints 的 OBJECT 参数列表 参数 类型 必填 说明 points Array 是 要显示在可视区域内的坐标点列表,[{latitude, longitude}] padding Array 否 坐标点形成的矩形边缘到地图边缘的距离,单位像素。格式为[上,右,下,左],安卓上只能识别数组第一项,上下左右的padding一致。开发者工具暂不支持padding参数。...

微信小程序API 查看位置

wx.getLocation(OBJECT) 获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用;当用户点击“显示在聊天顶部”时,此接口可继续调用。 OBJECT参数说明: 参数 类型 必填 说明 type String 否 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于wx.openLocation的坐标 success Function 是 接口调用成功的回调函数,返回内容详见返回参数说明。 fail Function 否 接口调用失败的回调函数 complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行) success返回参数说明: 参数 说明 最低版本 latitude 纬度,浮点数,范围为-90~90,负数表示南纬 longitude 经度,浮点数,范围为-180~180,负数表示西经 speed 速度,浮点数,单位m/s accuracy 位置的精确度 altitude 高度,单位 m 1.2.0 verticalAccuracy 垂直精度,单位 m(Android 无法获取,返回 0) 1.2.0 horizontalAccuracy 水平精度,单位 m 1.2.0 示例代码: wx.getLocation({ type: 'wgs84', success: function(res) { var latitude = res.latitude var longitude = res.longitude var speed = res.speed var accuracy = res.accuracy } }) wx.chooseLocation(OBJECT) 打开地图选择位置。 需要用户授权 scope.userLocation OBJECT参数说明: 参数 类型 必填 说明 success Function 是 接口调用成功的回调函数,返回内容详见返回参数说明。 fail Function 否 接口调用失败的回调函数 complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行) success返回参数说明: 参数 说明 name 位置名称 address 详细地址 latitude 纬度,浮点数,范围为-90~90,负数表示南纬 longitude 经度,浮点数,范围为-180~180,负数表示西经 wx.openLocation(OBJECT) ​使用微信内置地图查看位置。 需要用户授权 scope.userLocation OBJECT参数说明: 参数 类型 必填 说明...

微信小程序API 获取位置

wx.getLocation(OBJECT) 获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用;当用户点击“显示在聊天顶部”时,此接口可继续调用。 OBJECT参数说明: 参数 类型 必填 说明 type String 否 默认为”wgs84″返回gps坐标,”gcj02″返回可用于wx.openLocation的坐标 success Function 是 接口调用成功的回调函数,返回内容详见返回参数说明。 fail Function 否 接口调用失败的回调函数 complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行) success返回参数说明: 参数 说明 最低版本 latitude 纬度,浮点数,范围为-90~90,负数表示南纬   longitude 经度,浮点数,范围为-180~180,负数表示西经   speed 速度,浮点数,单位m/s   accuracy 位置的精确度   altitude 高度,单位 m 1.2.0 verticalAccuracy 垂直精度,单位 m(Android 无法获取,返回 0) 1.2.0 horizontalAccuracy 水平精度,单位 m 1.2.0 示例代码: wx.getLocation({ type: 'wgs84', success: function(res) { var latitude = res.latitude var longitude = res.longitude var speed = res.speed var accuracy = res.accuracy } }) wx.chooseLocation(OBJECT) 打开地图选择位置。 需要用户授权 scope.userLocation OBJECT参数说明: 参数 类型 必填 说明 success Function 是 接口调用成功的回调函数,返回内容详见返回参数说明。 cancel Function 否 用户取消时调用 fail Function 否 接口调用失败的回调函数 complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行) success返回参数说明: 参数 说明 name 位置名称 address 详细地址 latitude 纬度,浮点数,范围为-90~90,负数表示南纬 longitude 经度,浮点数,范围为-180~180,负数表示西经

微信小程序API 数据缓存

每个微信小程序都可以有自己的本地缓存,可以通过wx.setStorage(wx.setStorageSync)、wx.getStorage(wx.getStorageSync)、wx.clearStorage(wx.clearStorageSync)可以对本地缓存进行设置、获取和清理。同一个微信用户,同一个小程序 storage 上限为 10MB。localStorage 以用户维度隔离,同一台设备上,A 用户无法读取到 B 用户的数据。 注意: localStorage是永久存储的,但是我们不建议将关键信息全部存在localStorage,以防用户换设备的情况。 wx.setStorage(OBJECT) 将数据存储在本地缓存中指定的key中,会覆盖掉原来该key对应的内容,这是一个异步接口。 OBJECT参数说明: 参数 类型 必填 说明 key String 是 本地缓存中的指定的 key data Object/String 是 需要存储的内容 success Function 否 接口调用成功的回调函数 fail Function 否 接口调用失败的回调函数 complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行) 示例代码 wx.setStorage({ key:"key" data:"value" }) wx.setStorageSync(KEY,DATA) ​将data存储在本地缓存中指定的key中,会覆盖掉原来该key对应的内容,这是一个同步接口。 参数说明: 参数 类型 必填 说明 key String 是 本地缓存中的指定的key data Object/String 是 需要存储的内容 示例代码 try { wx.setStorageSync("key","value") } catch (e) { } wx.getStorage(OBJECT) 从本地缓存中异步获取指定key对应的内容。 OBJECT参数说明: 参数 类型 必填 说明 key String 是 本地缓存中的指定的 key success Function 是 接口调用的回调函数,res = {data: key对应的内容} fail Function 否 接口调用失败的回调函数 complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行) success返回参数说明: 参数 类型 说明 data String key对应的内容 示例代码: wx.getStorage({ key:'key', success: function(res){ console.log(res.data) } }) wx.getStorageSync(KEY) ​从本地缓存中同步获取指定key对应的内容。 参数说明: 参数 类型 必填 说明 key String 是 本地缓存中的指定的key...

微信小程序API 文件·描述文件状态的对象

Stats 描述文件状态的对象 属性 属性 说明 string mode 文件的类型和存取的权限,对应 POSIX stat.st_mode number size 文件大小,单位:B,对应 POSIX stat.st_size number lastAccessedTime 文件最近一次被存取或被执行的时间,UNIX 时间戳,对应 POSIX stat.st_atime number lastModifiedTime 文件最后一次被修改的时间,UNIX 时间戳,对应 POSIX stat.st_mtime 方法: boolean Stats.isDirectory() 判断当前文件是否一个目录 返回值 boolean 表示当前文件是否一个目录 boolean Stats.isFile() 判断当前文件是否一个普通文件 返回值 boolean 表示当前文件是否一个普通文件

微信小程序API 文件·文件管理器

FileSystemManager 基础库 1.9.9 开始支持,低版本需做兼容处理。 文件管理器 方法: FileSystemManager.access(Object object) 判断文件/目录是否存在 参数 Object object 属性 类型 默认值 必填 说明 path string 是 要判断是否存在的文件/目录路径 (本地路径) success function 否 接口调用成功的回调函数 fail function 否 接口调用失败的回调函数 complete function 否 接口调用结束的回调函数(调用成功、失败都会执行) object.fail 回调函数 参数 Object res 属性 类型 说明 errMsg string 错误信息 res.errMsg 的合法值 值 说明 最低版本 fail no such file or directory ${path} 文件/目录不存在 FileSystemManager.accessSync(string path) FileSystemManager.access 的同步版本 参数 string path 要判断是否存在的文件/目录路径 (本地路径) 错误 错误码 错误信息 说明 fail no such file or directory ${path} 文件/目录不存在 FileSystemManager.appendFile(Object object) 基础库 2.1.0 开始支持,低版本需做兼容处理。 在文件结尾追加内容 参数 Object object 属性 类型 默认值 必填 说明 filePath string 是 要追加内容的文件路径 (本地路径) data string/ArrayBuffer 是 要追加的文本或二进制数据 encoding string utf8 否 指定写入文件的字符编码 success function 否 接口调用成功的回调函数 fail function 否 接口调用失败的回调函数 complete function 否 接口调用结束的回调函数(调用成功、失败都会执行) object.encoding 的合法值...

微信小程序API 文件·获取文件信息

wx.getFileInfo(Object object) 基础库 1.4.0 开始支持,低版本需做兼容处理。 获取文件信息 参数 Object object 属性 类型 默认值 必填 说明 filePath string 是 本地文件路径 (本地路径) digestAlgorithm string ‘md5’ 否 计算文件摘要的算法 success function 否 接口调用成功的回调函数 fail function 否 接口调用失败的回调函数 complete function 否 接口调用结束的回调函数(调用成功、失败都会执行) object.digestAlgorithm 的合法值 值 说明 最低版本 md5 md5 算法 sha1 sha1 算法 object.success 回调函数 参数 Object res 属性 类型 说明 size number 文件大小,以字节为单位 digest string 按照传入的 digestAlgorithm 计算得出的的文件摘要 示例代码 wx.getFileInfo({ success (res) { console.log(res.size) console.log(res.digest) } })

微信小程序API 文件·获取本地文件信息

wx.getSavedFileInfo(Object object) 获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用 wx.getFileInfo() 接口。 参数 Object object 属性 类型 默认值 必填 说明 filePath string 是 文件路径 (本地路径) success function 否 接口调用成功的回调函数 fail function 否 接口调用失败的回调函数 complete function 否 接口调用结束的回调函数(调用成功、失败都会执行) object.success 回调函数 参数 Object res 属性 类型 说明 size number 文件大小,单位 B createTime number 文件保存时的时间戳,从1970/01/01 08:00:00 到该时刻的秒数 示例代码 wx.getSavedFileList({ success (res) { console.log(res.fileList) } })

微信小程序API 文件·获取已保存的本地缓存文件列表

wx.getSavedFileList(Object object) 获取该小程序下已保存的本地缓存文件列表 参数 Object object 属性 类型 默认值 必填 说明 success function 否 接口调用成功的回调函数 fail function 否 接口调用失败的回调函数 complete function 否 接口调用结束的回调函数(调用成功、失败都会执行) object.success 回调函数 参数 Object res 属性 类型 说明 fileList Array.<Object> 文件数组,每一项是一个 FileItem res.fileList 的结构 属性 类型 说明 filePath string 文件路径 (本地路径) size number 本地文件大小,以字节为单位 createTime number 文件保存时的时间戳,从1970/01/01 08:00:00 到当前时间的秒数 示例代码 wx.getSavedFileList({ success (res) { console.log(res.fileList) } })