diff --git a/ebike-maintenance/utils/map.js b/ebike-maintenance/utils/map.js index 314e8e5..8ac73f0 100644 --- a/ebike-maintenance/utils/map.js +++ b/ebike-maintenance/utils/map.js @@ -46,9 +46,80 @@ export const getLoalcation = (oMap, success, fail, nomove) => { }); } +function test(a) { + function b(d) { + var e = c.requestConfig; + wx.request({ + url: "https://restapi.amap.com/v3/geocode/regeo", + data: { + key: c.key, + location: d, + extensions: "all", + s: e.s, + platform: e.platform, + appname: c.key, + sdkversion: e.sdkversion, + logversion: e.logversion + }, + method: "GET", + header: { + "content-type": "application/json" + }, + success: function(g) { + if (g.data.status && "1" == g.data.status) { + g = g.data.regeocode; + var h = g.addressComponent, + f = [], + k = g.roads[0].name + "\u9644\u8fd1", + m = d.split(",")[0], + n = d.split(",")[1]; + if (g.pois && + g.pois[0]) { + k = g.pois[0].name + "\u9644\u8fd1"; + var l = g.pois[0].location; + l && (m = parseFloat(l.split(",")[0]), n = parseFloat(l.split(",")[1])) + } + h.provice && f.push(h.provice); + h.city && f.push(h.city); + h.district && f.push(h.district); + h.streetNumber && h.streetNumber.street && h.streetNumber.number ? (f.push(h + .streetNumber.street), f.push(h.streetNumber.number)) : f.push(g.roads[0].name); + f = f.join(""); + a.success([{ + iconPath: a.iconPath, + width: a.iconWidth, + height: a.iconHeight, + name: f, + desc: k, + longitude: m, + latitude: n, + id: 0, + regeocodeData: g + }]) + } else a.fail({ + errCode: g.data.infocode, + errMsg: g.data.info + }) + }, + fail: function(g) { + a.fail({ + errCode: "0", + errMsg: g.errMsg || "" + }) + } + }) + } + var c = this; + a.location ? b(a.location) : c.getWxLocation(a, function(d) { + b(d) + }) +}; + //逆解析地址 export const reverseGeocoder = (mapsdk, longitude, latitude, success, fail) => { + mapsdk.getRegeo({ + location:`${longitude},${latitude}`, success: function(res) { const { name, @@ -486,10 +557,10 @@ export function direction({ destination: `${elng},${elat}`, success: (res) => { let points = []; - let distance=0; + let distance = 0; if (res.paths && res.paths[0] && res.paths[0].steps) { let steps = res.paths[0].steps; - distance=res.paths[0].distance; + distance = res.paths[0].distance; for (let i = 0; i < steps.length; i++) { let poLen = steps[i].polyline.split(';'); for (let j = 0; j < poLen.length; j++) { @@ -506,7 +577,7 @@ export function direction({ sdistance = cnt + "km"; } const data = { - arrPoint:points, + arrPoint: points, distance: sdistance } if (success) success(data);