async/await 还是同步怎么办?
get: async function(e) { let $that = this; let $distance = await getDistance($that.data.info._point); if ($distance <= 8000) { //step1 } else { //step2 } },let getDistance = async (point) => { let $geo = null; await wx.getLocation({ type: "gcj02", altitude: true, success: res => { $geo = [res.longitude, res.latitude]; }, fail: err => { $geo = [180, -80]; }, complete: () => { let $pointJson = JSON.stringify(point); let $pointGeo = JSON.parse($pointJson); let $point = $pointGeo.coordinates; let $rad = 6378137; let $rad1 = parseFloat($geo[1]) * Math.PI / 180.0; let $rad2 = parseFloat($point[1]) * Math.PI / 180.0; let $sub1 = $rad1 - $rad2; let $sub2 = parseFloat($geo[0]) * Math.PI / 180.0 - parseFloat($point[0]) * Math.PI / 180.0; let $sub = (2 * $rad * Math.asin(Math.sqrt(Math.pow(Math.sin($sub1 / 2), 2) + Math.cos($rad1) * Math.cos($rad2) * Math.pow(Math.sin($sub2 / 2), 2)))).toFixed(0); return parseInt($sub); } })} |
我在get函数中会直接跑到step2,然后才到return parseInt($sub)
