@uni/location
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

location

npm

安装

$ npm install @uni/location --save

or

$ npm install @uni/apis --save

示例

import { getLocation } from '@uni/location';

getLocation({
  success: (res) => {
    console.log('success', res);
  },
  fail: (res) => {
    console.log('fail', res);
  },
  complete: (res) => {
    console.log('complete', res);
  }
});

// promise
getLocation().then(response => {})
  .catch(error => {})
  .finally(res => {});

方法

getLocation(options)

获取当前的地理位置,该接口返回的均为WGS84(World Geodetic System)坐标,即GPS坐标。

支持

browser miniApp wechatMiniprogram bytedanceMicroApp baiduSmartProgram kuaiShouMiniProgram

参数

成员 类型 描述 必选 默认值
options object  ✔️ -
options.success Function  成功的回调 -
options.fail Function  失败的回调 -
options.complete Function  结束的回调 (调用成功、失败都会执行) -

返回

成员 类型 描述
latitude string  纬度
longitude string  经度
accuracy string  位置的精确度
horizontalAccuracy string  水平精度

openLocation

使用内置地图查看位置。各平台内置地图均要求火星坐标,即使用 gcj02 国测局坐标系。

示例

import { openLocation } from '@uni/location';

openLocation({
  longitude: '120.126293',
  latitude: '30.274653',
  name: '黄龙万科中心',
  address: '学院路77号',
  success: (res) => {
    console.log('success', res);
  },
  fail: (res) => {
    console.log('fail', res);
  },
  complete: (res) => {
    console.log('complete', res);
  }
});

// promise
openLocation({
  longitude: '120.126293',
  latitude: '30.274653',
  name: '黄龙万科中心',
  address: '学院路77号'})
  .then(response => {})
  .catch(error => {})
  .finally(res => {});

支持

miniApp wechatMiniprogram bytedanceMicroApp baiduSmartProgram

参数

成员 类型 描述 必选 默认值
options object  ✔️ -
options.latitude string  纬度 ✔️ -
options.longtitude string 经度 ✔️ -
options.name string  位置名 ✔️ -
options.scale number 缩放比例,范围5~18 18
options.address string  地址的详细说明 ✔️ -
options.success Function  成功的回调 -
options.fail Function  失败的回调 -
options.complete Function  结束的回调 (调用成功、失败都会执行) -

Readme

Keywords

none

Package Sidebar

Install

npm i @uni/location

Weekly Downloads

2

Version

1.0.9

License

BSD-3-Clause

Unpacked Size

129 kB

Total Files

112

Last publish

Collaborators

  • bunko
  • rax-publisher