1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- // 计算点位距离
- export const distanceCalculate = (num) => {
- const num_ = Number(num);
- if (typeof num_ === 'number') {
- if (num_ < 1000) {
- return `${num_.toFixed(1)}米`
- } else {
- const n = (num_ / 1000).toFixed(1);
- return `${n}公里`
- };
- }
- return num_ || num
- }
- // 拨打电话
- export const PhoneCall = (tel) => {
- return new Promise((resolve, reject) => {
- if (tel) {
- uni.makePhoneCall({
- phoneNumber: tel + '',
- success: res => {
- resolve()
- },
- fail: () => {
- reject()
- }
- });
- } else {
- uni.showToast({
- title: '暂未设置电话'
- });
- }
- })
- }
- // 导航
- export const getMapLocation = (parmas = {}) => {
- const { latitude, longitude, name, detailedAddress } = parmas
- uni.openLocation({
- latitude: parseFloat(latitude), // 要去的地址经度,浮点数
- longitude: parseFloat(longitude), // 要去的地址纬度,浮点数
- name: name, // 位置名
- address: detailedAddress, // 要去的地址详情说明
- scale: 16, // 地图缩放级别,整形值,范围从1~28。默认为最大
- });
- }
- export const getLocation = () => {
- return new Promise((resolve, reject) => {
- try {
- uni.getLocation({
- type: 'wgs84', // 返回可以用于uni.openLocation的经纬度
- success: (res) => {
- console.log("getLocation 1111111111111111111= ", res)
- // this.selfLatitude = res.longitude;
- // this.selfLongitude = res.latitude;
- resolve(res)
- },
- fail: (err) => {
- console.log('获取位置失败2 :', err);
- reject()
- }
- });
- } catch (error) {
- console.log('获取位置失败 1:', error);
- //TODO handle the exception
- }
- })
- }
-
|