当前位置:   article > 正文

uniapp中位置授权提示_uni.authorize

uni.authorize

前言

因项目的需求,需要,首次登录小程序的用户,一进来就显示一个弹窗,提示

点击允许打印的结果

官网地址     uni.getSetting   获取用户的当前设置。

出现弹窗的原因是因为使用 了 uni.authorize 这个属性 

还需要在  manifest.json 中配置

总代码 

实现弹层的方法也就是 下面那两个方法以及 在 manifest.json 文件中配置,后面的  getLocation 以及 后续补充的  chooseSpot 是获取当前城市位置 以及经纬度的方法

获取位置授权代码

在methods中      

  1. isGetLocation(a = "scope.userLocation") { //检查当前是否已经授权访问scope属性
  2. var _this = this;
  3. uni.getSetting({
  4. success(res) {
  5. console.log(res)
  6. if (!res.authSetting[a]) { //每次进入程序判断当前是否获得授权,如果没有就去获得授权,如果获得授权,就直接获取当前地理位置
  7. _this.getAuthorizeInfo()
  8. } else {
  9. _this.getLocation();
  10. }
  11. }
  12. });
  13. },
  14. getAuthorizeInfo(a = "scope.userLocation") { // uniapp弹窗弹出获取授权(地理,个人微信信息等授权信息)弹窗
  15. var _this = this;
  16. uni.authorize({
  17. scope: a,
  18. success() { //允许授权
  19. _this.getLocation();
  20. }
  21. })
  22. },
  23. getLocation() {
  24. uni.getLocation({
  25. type: 'gcj02',
  26. geocode: true,
  27. success: res => {
  28. this.latitude = res.latitude
  29. this.longitude = res.longitude
  30. let latlng = [this.latitude, this.longitude]
  31. console.log('当前位置的经纬度', latlng);
  32. // console.log(res, '位置信息打印查看结果');
  33. },
  34. address: (res) => {
  35. console.log('address', res);
  36. }
  37. });
  38. },
  1. onShow() {
  2. this.getLocation()
  3. },

提示,要注意一个问题,就是当 测试版发布为线上版本时,微信小程序会审核uni.getLocation这个api的接口,

后续

若不想审核 uni.getLocation这个api的接口, 可以使用 下面的方法

引入文件

 import amap from '../../common/amap-wx.130.js'

methods中

  1. isGetLocation(a = "scope.userLocation") { //检查当前是否已经授权访问scope属性
  2. var _this = this;
  3. uni.getSetting({
  4. success(res) {
  5. console.log('用户同意获取地理位置设置 getSetting', res)
  6. if (!res.authSetting[a]) { //每次进入程序判断当前是否获得授权,如果没有就去获得授权,如果获得授权,就直接获取当前地理位置
  7. _this.getAuthorizeInfo()
  8. } else {
  9. _this.chooseSpot();
  10. }
  11. },
  12. fail(err) {
  13. console.log('用户拒绝授权', err);
  14. }
  15. });
  16. },
  17. getAuthorizeInfo(a = "scope.userLocation") { // uniapp弹窗弹出获取授权(地理,个人微信信息等授权信息)弹窗
  18. var _this = this;
  19. uni.authorize({
  20. scope: a,
  21. success() { //允许授权
  22. console.log('已授权');
  23. _this.getStationList()
  24. },
  25. fail(err) {
  26. console.log('用户拒绝', err);
  27. _this.getStationList()
  28. }
  29. })
  30. },
  31. chooseSpot() { // 高德地图的方法,获取地址
  32. this.amapPlugin.getRegeo({
  33. success: (data) => {
  34. this.latitude = data[0].latitude
  35. this.longitude = data[0].longitude
  36. this.city = data[0].regeocodeData.addressComponent.district
  37. console.log('用户当前城市显示的是:', this.city);
  38. this.updateUserCity(this.city)
  39. this.getStationList()
  40. }
  41. });
  42. },
  1. onLoad(){
  2. this.amapPlugin = new amap.AMapWX({
  3. key: this.key
  4. });
  5. this.isGetLocation()
  6. }
  1. data 里面定义
  2. // 在高德小程序中申请的key
  3. key: '7ae9ca9d5e47feb6d3c69XXXXXXXX',
  4. amapPlugin: null

配置项

  1. "permission": {
  2. "scope.userLocation": {
  3. "desc": "获取您的位置"
  4. }
  5. },
  6. "lazyCodeLoading": "requiredComponents",
  7. "requiredPrivateInfos": [
  8. "getLocation",
  9. "onLocationChange",
  10. "startLocationUpdateBackground",
  11. "chooseAddress"
  12. ]

js文件

  1. function AMapWX(a) {
  2. this.key = a.key;
  3. this.requestConfig = {
  4. key: a.key,
  5. s: "rsx",
  6. platform: "WXJS",
  7. appname: a.key,
  8. sdkversion: "1.2.0",
  9. logversion: "2.0"
  10. };
  11. this.MeRequestConfig = {
  12. key: a.key,
  13. serviceName: "https://restapi.amap.com/rest/me"
  14. }
  15. }
  16. AMapWX.prototype.getWxLocation = function(a, b) {
  17. uni.getLocation({
  18. type: "gcj02",
  19. success: function(c) {
  20. c = c.longitude + "," + c.latitude;
  21. uni.setStorage({
  22. key: "userLocation",
  23. data: c
  24. });
  25. b(c)
  26. },
  27. fail: function(c) {
  28. uni.getStorage({
  29. key: "userLocation",
  30. success: function(d) {
  31. d.data && b(d
  32. .data)
  33. }
  34. });
  35. console.log(c);
  36. a.fail({
  37. errCode: "0",
  38. errMsg: c.errMsg || ""
  39. })
  40. }
  41. })
  42. };
  43. AMapWX.prototype.getMEKeywordsSearch = function(a) {
  44. if (!a.options) return a.fail({
  45. errCode: "0",
  46. errMsg: "\u7f3a\u5c11\u5fc5\u8981\u53c2\u6570"
  47. });
  48. var b = a.options,
  49. c = this.MeRequestConfig,
  50. d = {
  51. key: c.key,
  52. s: "rsx",
  53. platform: "WXJS",
  54. appname: a.key,
  55. sdkversion: "1.2.0",
  56. logversion: "2.0"
  57. };
  58. b.layerId && (d.layerId = b.layerId);
  59. b.keywords && (d.keywords = b.keywords);
  60. b.city && (d.city = b.city);
  61. b.filter && (d.filter = b.filter);
  62. b.sortrule && (d.sortrule = b.sortrule);
  63. b.pageNum && (d.pageNum = b.pageNum);
  64. b.pageSize && (d.pageSize = b.pageSize);
  65. b.sig && (d.sig =
  66. b.sig);
  67. uni.request({
  68. url: c.serviceName + "/cpoint/datasearch/local",
  69. data: d,
  70. method: "GET",
  71. header: {
  72. "content-type": "application/json"
  73. },
  74. success: function(e) {
  75. (e = e.data) && e.status && "1" === e.status && 0 === e.code ? a.success(e.data) : a.fail({
  76. errCode: "0",
  77. errMsg: e
  78. })
  79. },
  80. fail: function(e) {
  81. a.fail({
  82. errCode: "0",
  83. errMsg: e.errMsg || ""
  84. })
  85. }
  86. })
  87. };
  88. AMapWX.prototype.getMEIdSearch = function(a) {
  89. if (!a.options) return a.fail({
  90. errCode: "0",
  91. errMsg: "\u7f3a\u5c11\u5fc5\u8981\u53c2\u6570"
  92. });
  93. var b = a.options,
  94. c = this.MeRequestConfig,
  95. d = {
  96. key: c.key,
  97. s: "rsx",
  98. platform: "WXJS",
  99. appname: a.key,
  100. sdkversion: "1.2.0",
  101. logversion: "2.0"
  102. };
  103. b.layerId && (d.layerId = b.layerId);
  104. b.id && (d.id = b.id);
  105. b.sig && (d.sig = b.sig);
  106. uni.request({
  107. url: c.serviceName + "/cpoint/datasearch/id",
  108. data: d,
  109. method: "GET",
  110. header: {
  111. "content-type": "application/json"
  112. },
  113. success: function(e) {
  114. (e = e.data) && e.status && "1" === e.status &&
  115. 0 === e.code ? a.success(e.data) : a.fail({
  116. errCode: "0",
  117. errMsg: e
  118. })
  119. },
  120. fail: function(e) {
  121. a.fail({
  122. errCode: "0",
  123. errMsg: e.errMsg || ""
  124. })
  125. }
  126. })
  127. };
  128. AMapWX.prototype.getMEPolygonSearch = function(a) {
  129. if (!a.options) return a.fail({
  130. errCode: "0",
  131. errMsg: "\u7f3a\u5c11\u5fc5\u8981\u53c2\u6570"
  132. });
  133. var b = a.options,
  134. c = this.MeRequestConfig,
  135. d = {
  136. key: c.key,
  137. s: "rsx",
  138. platform: "WXJS",
  139. appname: a.key,
  140. sdkversion: "1.2.0",
  141. logversion: "2.0"
  142. };
  143. b.layerId && (d.layerId = b.layerId);
  144. b.keywords && (d.keywords = b.keywords);
  145. b.polygon && (d.polygon = b.polygon);
  146. b.filter && (d.filter = b.filter);
  147. b.sortrule && (d.sortrule = b.sortrule);
  148. b.pageNum && (d.pageNum = b.pageNum);
  149. b.pageSize && (d.pageSize = b.pageSize);
  150. b.sig && (d.sig = b.sig);
  151. uni.request({
  152. url: c.serviceName + "/cpoint/datasearch/polygon",
  153. data: d,
  154. method: "GET",
  155. header: {
  156. "content-type": "application/json"
  157. },
  158. success: function(e) {
  159. (e = e.data) && e.status && "1" === e.status && 0 === e.code ? a.success(e.data) : a.fail({
  160. errCode: "0",
  161. errMsg: e
  162. })
  163. },
  164. fail: function(e) {
  165. a.fail({
  166. errCode: "0",
  167. errMsg: e.errMsg || ""
  168. })
  169. }
  170. })
  171. };
  172. AMapWX.prototype.getMEaroundSearch = function(a) {
  173. if (!a.options) return a.fail({
  174. errCode: "0",
  175. errMsg: "\u7f3a\u5c11\u5fc5\u8981\u53c2\u6570"
  176. });
  177. var b = a.options,
  178. c = this.MeRequestConfig,
  179. d = {
  180. key: c.key,
  181. s: "rsx",
  182. platform: "WXJS",
  183. appname: a.key,
  184. sdkversion: "1.2.0",
  185. logversion: "2.0"
  186. };
  187. b.layerId && (d.layerId = b.layerId);
  188. b.keywords && (d.keywords = b.keywords);
  189. b.center && (d.center = b.center);
  190. b.radius && (d.radius = b.radius);
  191. b.filter && (d.filter = b.filter);
  192. b.sortrule && (d.sortrule = b.sortrule);
  193. b.pageNum && (d.pageNum = b.pageNum);
  194. b.pageSize &&
  195. (d.pageSize = b.pageSize);
  196. b.sig && (d.sig = b.sig);
  197. uni.request({
  198. url: c.serviceName + "/cpoint/datasearch/around",
  199. data: d,
  200. method: "GET",
  201. header: {
  202. "content-type": "application/json"
  203. },
  204. success: function(e) {
  205. (e = e.data) && e.status && "1" === e.status && 0 === e.code ? a.success(e.data) : a.fail({
  206. errCode: "0",
  207. errMsg: e
  208. })
  209. },
  210. fail: function(e) {
  211. a.fail({
  212. errCode: "0",
  213. errMsg: e.errMsg || ""
  214. })
  215. }
  216. })
  217. };
  218. AMapWX.prototype.getGeo = function(a) {
  219. var b = this.requestConfig,
  220. c = a.options;
  221. b = {
  222. key: this.key,
  223. extensions: "all",
  224. s: b.s,
  225. platform: b.platform,
  226. appname: this.key,
  227. sdkversion: b.sdkversion,
  228. logversion: b.logversion
  229. };
  230. c.address && (b.address = c.address);
  231. c.city && (b.city = c.city);
  232. c.batch && (b.batch = c.batch);
  233. c.sig && (b.sig = c.sig);
  234. uni.request({
  235. url: "https://restapi.amap.com/v3/geocode/geo",
  236. data: b,
  237. method: "GET",
  238. header: {
  239. "content-type": "application/json"
  240. },
  241. success: function(d) {
  242. (d = d.data) && d.status && "1" === d.status ? a.success(d) : a.fail({
  243. errCode: "0",
  244. errMsg: d
  245. })
  246. },
  247. fail: function(d) {
  248. a.fail({
  249. errCode: "0",
  250. errMsg: d.errMsg || ""
  251. })
  252. }
  253. })
  254. };
  255. AMapWX.prototype.getRegeo = function(a) {
  256. function b(d) {
  257. var e = c.requestConfig;
  258. uni.request({
  259. url: "https://restapi.amap.com/v3/geocode/regeo",
  260. data: {
  261. key: c.key,
  262. location: d,
  263. extensions: "all",
  264. s: e.s,
  265. platform: e.platform,
  266. appname: c.key,
  267. sdkversion: e.sdkversion,
  268. logversion: e.logversion
  269. },
  270. method: "GET",
  271. header: {
  272. "content-type": "application/json"
  273. },
  274. success: function(g) {
  275. if (g.data.status && "1" == g.data.status) {
  276. g = g.data.regeocode;
  277. var h = g.addressComponent,
  278. f = [],
  279. k = g.roads[0].name + "\u9644\u8fd1",
  280. m = d.split(",")[0],
  281. n = d.split(",")[1];
  282. if (g.pois &&
  283. g.pois[0]) {
  284. k = g.pois[0].name + "\u9644\u8fd1";
  285. var l = g.pois[0].location;
  286. l && (m = parseFloat(l.split(",")[0]), n = parseFloat(l.split(",")[1]))
  287. }
  288. h.provice && f.push(h
  289. .provice);
  290. h.city && f.push(h.city);
  291. h.district && f.push(h.district);
  292. h.streetNumber && h.streetNumber.street && h.streetNumber.number ? (f.push(h.streetNumber.street), f
  293. .push(h.streetNumber.number)) : f.push(g.roads[0].name);
  294. f = f.join("");
  295. a.success([{
  296. iconPath: a.iconPath,
  297. width: a.iconWidth,
  298. height: a.iconHeight,
  299. name: f,
  300. desc: k,
  301. longitude: m,
  302. latitude: n,
  303. id: 0,
  304. regeocodeData: g
  305. }])
  306. } else a.fail({
  307. errCode: g.data.infocode,
  308. errMsg: g.data.info
  309. })
  310. },
  311. fail: function(g) {
  312. a.fail({
  313. errCode: "0",
  314. errMsg: g.errMsg || ""
  315. })
  316. }
  317. })
  318. }
  319. var c = this;
  320. a.location ? b(a.location) : c.getWxLocation(a, function(d) {
  321. b(d)
  322. })
  323. };
  324. AMapWX.prototype.getWeather = function(a) {
  325. function b(g) {
  326. var h = "base";
  327. a.type && "forecast" == a.type && (h = "all");
  328. uni.request({
  329. url: "https://restapi.amap.com/v3/weather/weatherInfo",
  330. data: {
  331. key: d.key,
  332. city: g,
  333. extensions: h,
  334. s: e.s,
  335. platform: e.platform,
  336. appname: d.key,
  337. sdkversion: e
  338. .sdkversion,
  339. logversion: e.logversion
  340. },
  341. method: "GET",
  342. header: {
  343. "content-type": "application/json"
  344. },
  345. success: function(f) {
  346. if (f.data.status && "1" == f.data.status)
  347. if (f.data.lives) {
  348. if ((f = f.data.lives) && 0 < f.length) {
  349. f = f[0];
  350. var k = {
  351. city: {
  352. text: "\u57ce\u5e02",
  353. data: f.city
  354. },
  355. weather: {
  356. text: "\u5929\u6c14",
  357. data: f.weather
  358. },
  359. temperature: {
  360. text: "\u6e29\u5ea6",
  361. data: f.temperature
  362. },
  363. winddirection: {
  364. text: "\u98ce\u5411",
  365. data: f.winddirection + "\u98ce"
  366. },
  367. windpower: {
  368. text: "\u98ce\u529b",
  369. data: f.windpower + "\u7ea7"
  370. },
  371. humidity: {
  372. text: "\u6e7f\u5ea6",
  373. data: f.humidity + "%"
  374. }
  375. };
  376. k.liveData = f;
  377. a.success(k)
  378. }
  379. } else f.data.forecasts && f.data.forecasts[0] && a.success({
  380. forecast: f.data.forecasts[0]
  381. });
  382. else a.fail({
  383. errCode: f.data.infocode,
  384. errMsg: f.data.info
  385. })
  386. },
  387. fail: function(f) {
  388. a.fail({
  389. errCode: "0",
  390. errMsg: f.errMsg || ""
  391. })
  392. }
  393. })
  394. }
  395. function c(g) {
  396. uni.request({
  397. url: "https://restapi.amap.com/v3/geocode/regeo",
  398. data: {
  399. key: d.key,
  400. location: g,
  401. extensions: "all",
  402. s: e.s,
  403. platform: e.platform,
  404. appname: d.key,
  405. sdkversion: e.sdkversion,
  406. logversion: e.logversion
  407. },
  408. method: "GET",
  409. header: {
  410. "content-type": "application/json"
  411. },
  412. success: function(h) {
  413. if (h.data.status && "1" == h.data.status) {
  414. h = h.data.regeocode;
  415. if (h
  416. .addressComponent) var f = h.addressComponent.adcode;
  417. else h.aois && 0 < h.aois.length && (f = h.aois[0].adcode);
  418. b(f)
  419. } else a.fail({
  420. errCode: h.data.infocode,
  421. errMsg: h.data.info
  422. })
  423. },
  424. fail: function(h) {
  425. a.fail({
  426. errCode: "0",
  427. errMsg: h.errMsg || ""
  428. })
  429. }
  430. })
  431. }
  432. var d = this,
  433. e = d.requestConfig;
  434. a.city ? b(a.city) : d.getWxLocation(a, function(g) {
  435. c(g)
  436. })
  437. };
  438. AMapWX.prototype.getPoiAround = function(a) {
  439. function b(e) {
  440. e = {
  441. key: c.key,
  442. location: e,
  443. s: d.s,
  444. platform: d.platform,
  445. appname: c.key,
  446. sdkversion: d.sdkversion,
  447. logversion: d.logversion
  448. };
  449. a.querytypes && (e.types = a.querytypes);
  450. a.querykeywords && (e.keywords = a.querykeywords);
  451. uni.request({
  452. url: "https://restapi.amap.com/v3/place/around",
  453. data: e,
  454. method: "GET",
  455. header: {
  456. "content-type": "application/json"
  457. },
  458. success: function(g) {
  459. if (g.data.status && "1" == g.data.status) {
  460. if ((g = g.data) && g.pois) {
  461. for (var h = [], f = 0; f < g.pois.length; f++) {
  462. var k = 0 ==
  463. f ? a.iconPathSelected : a.iconPath;
  464. h.push({
  465. latitude: parseFloat(g.pois[f].location.split(",")[1]),
  466. longitude: parseFloat(g.pois[f]
  467. .location.split(",")[0]),
  468. iconPath: k,
  469. width: 22,
  470. height: 32,
  471. id: f,
  472. name: g.pois[f].name,
  473. address: g.pois[f].address
  474. })
  475. }
  476. a.success({
  477. markers: h,
  478. poisData: g.pois
  479. })
  480. }
  481. } else a.fail({
  482. errCode: g.data.infocode,
  483. errMsg: g.data.info
  484. })
  485. },
  486. fail: function(g) {
  487. a.fail({
  488. errCode: "0",
  489. errMsg: g.errMsg || ""
  490. })
  491. }
  492. })
  493. }
  494. var c = this,
  495. d = c.requestConfig;
  496. a.location ? b(a.location) : c.getWxLocation(a, function(e) {
  497. b(e)
  498. })
  499. };
  500. AMapWX.prototype.getStaticmap = function(a) {
  501. function b(e) {
  502. c.push("location=" + e);
  503. a.zoom && c.push("zoom=" + a.zoom);
  504. a.size && c.push("size=" + a.size);
  505. a.scale && c.push("scale=" + a.scale);
  506. a.markers && c.push("markers=" + a.markers);
  507. a.labels && c.push("labels=" + a.labels);
  508. a.paths && c.push("paths=" + a.paths);
  509. a.traffic && c.push("traffic=" + a.traffic);
  510. e = "https://restapi.amap.com/v3/staticmap?" + c.join("&");
  511. a.success({
  512. url: e
  513. })
  514. }
  515. var c = [];
  516. c.push("key=" + this.key);
  517. var d = this.requestConfig;
  518. c.push("s=" + d.s);
  519. c.push("platform=" + d.platform);
  520. c.push("appname=" + d.appname);
  521. c.push("sdkversion=" + d.sdkversion);
  522. c.push("logversion=" + d.logversion);
  523. a.location ? b(a.location) : this.getWxLocation(a, function(e) {
  524. b(e)
  525. })
  526. };
  527. AMapWX.prototype.getInputtips = function(a) {
  528. var b = Object.assign({}, this.requestConfig);
  529. a.location && (b.location = a.location);
  530. a.keywords && (b.keywords = a.keywords);
  531. a.type && (b.type = a.type);
  532. a.city && (b.city = a.city);
  533. a.citylimit && (b.citylimit = a.citylimit);
  534. uni.request({
  535. url: "https://restapi.amap.com/v3/assistant/inputtips",
  536. data: b,
  537. method: "GET",
  538. header: {
  539. "content-type": "application/json"
  540. },
  541. success: function(c) {
  542. c && c.data && c.data.tips && a.success({
  543. tips: c.data.tips
  544. })
  545. },
  546. fail: function(c) {
  547. a.fail({
  548. errCode: "0",
  549. errMsg: c.errMsg ||
  550. ""
  551. })
  552. }
  553. })
  554. };
  555. AMapWX.prototype.getDrivingRoute = function(a) {
  556. var b = Object.assign({}, this.requestConfig);
  557. a.origin && (b.origin = a.origin);
  558. a.destination && (b.destination = a.destination);
  559. a.strategy && (b.strategy = a.strategy);
  560. a.waypoints && (b.waypoints = a.waypoints);
  561. a.avoidpolygons && (b.avoidpolygons = a.avoidpolygons);
  562. a.avoidroad && (b.avoidroad = a.avoidroad);
  563. uni.request({
  564. url: "https://restapi.amap.com/v3/direction/driving",
  565. data: b,
  566. method: "GET",
  567. header: {
  568. "content-type": "application/json"
  569. },
  570. success: function(c) {
  571. c && c.data && c.data.route && a.success({
  572. paths: c.data.route.paths,
  573. taxi_cost: c.data.route.taxi_cost || ""
  574. })
  575. },
  576. fail: function(c) {
  577. a.fail({
  578. errCode: "0",
  579. errMsg: c.errMsg || ""
  580. })
  581. }
  582. })
  583. };
  584. AMapWX.prototype.getWalkingRoute = function(a) {
  585. var b = Object.assign({}, this.requestConfig);
  586. a.origin && (b.origin = a.origin);
  587. a.destination && (b.destination = a.destination);
  588. uni.request({
  589. url: "https://restapi.amap.com/v3/direction/walking",
  590. data: b,
  591. method: "GET",
  592. header: {
  593. "content-type": "application/json"
  594. },
  595. success: function(c) {
  596. c && c.data && c.data.route && a
  597. .success({
  598. paths: c.data.route.paths
  599. })
  600. },
  601. fail: function(c) {
  602. a.fail({
  603. errCode: "0",
  604. errMsg: c.errMsg ||
  605. ""
  606. })
  607. }
  608. })
  609. };
  610. AMapWX.prototype.getTransitRoute = function(a) {
  611. var b = Object.assign({}, this.requestConfig);
  612. a.origin && (b.origin = a.origin);
  613. a.destination && (b.destination = a.destination);
  614. a.strategy && (b.strategy = a.strategy);
  615. a.city && (b.city = a.city);
  616. a.cityd && (b.cityd = a.cityd);
  617. uni.request({
  618. url: "https://restapi.amap.com/v3/direction/transit/integrated",
  619. data: b,
  620. method: "GET",
  621. header: {
  622. "content-type": "application/json"
  623. },
  624. success: function(c) {
  625. c && c.data && c.data.route && (c = c.data.route, a.success({
  626. distance: c.distance || "",
  627. taxi_cost: c.taxi_cost ||
  628. "",
  629. transits: c.transits
  630. }))
  631. },
  632. fail: function(c) {
  633. a.fail({
  634. errCode: "0",
  635. errMsg: c.errMsg || ""
  636. })
  637. }
  638. })
  639. };
  640. AMapWX.prototype.getRidingRoute = function(a) {
  641. var b = Object.assign({}, this.requestConfig);
  642. a.origin && (b.origin = a.origin);
  643. a.destination && (b.destination = a.destination);
  644. uni.request({
  645. url: "https://restapi.amap.com/v3/direction/riding",
  646. data: b,
  647. method: "GET",
  648. header: {
  649. "content-type": "application/json"
  650. },
  651. success: function(c) {
  652. c && c.data && c.data.route && a
  653. .success({
  654. paths: c.data.route.paths
  655. })
  656. },
  657. fail: function(c) {
  658. a.fail({
  659. errCode: "0",
  660. errMsg: c.errMsg ||
  661. ""
  662. })
  663. }
  664. })
  665. };
  666. module.exports.AMapWX = AMapWX;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/548556
推荐阅读