diff --git a/index/index.js b/index/index.js index 3b4274b..6741b45 100644 --- a/index/index.js +++ b/index/index.js @@ -645,10 +645,10 @@ Page({ const isBest = [] mallLocationArr.forEach(item => { const num = that.getDistances(latitudeNow, longitudeNow, item.latitude, item.longitude) - isBest.push(num.distance_str) + isBest.push(num.distance) }) console.log(isBest, 'isBest'); - const winer = isBest.bubbleSort() + const winer = this.bloob(isBest) console.log(winer, 'winer'); } }) @@ -661,9 +661,8 @@ Page({ * @return: distanceObj: { distance , distance_str } */ getDistances(lat1, lng1, lat2, lng2) { - - function rad(d) { - return d * Math.PI / 180.0; + function rad(num) { + return num * Math.PI / 180.0; } var radLat1 = rad(lat1); var radLat2 = rad(lat2); @@ -690,6 +689,23 @@ Page({ return objData }, + bloob(arr) { + const tempArr = arr + for (let i = 0; i < tempArr.length - 1; i++) { + for (let j = 0; j < tempArr.length - 1 - i; j++) { + if (tempArr[j] > tempArr[j + 1]) { + let temp = tempArr[j]; + tempArr[j] = tempArr[j + 1]; + tempArr[j + 1] = temp; + + } + + } + } + return tempArr + }, + + onShow: function () { this.mallSync() console.log(app.globalData.mouldType, "mouldType")