gdconf.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //高德小程序SDK
  2. var amapFile = require('amap-wx.js');
  3. /***************
  4. * 此处为高地地图小程序的key
  5. ****************/
  6. var map = new amapFile.AMapWX({ key: 'eb9f7f7926714826325c3adfe0c6b93b' });
  7. var watcher = true;
  8. //公共模块
  9. module.exports = {
  10. //实例化高德地图
  11. map: map,
  12. /***************
  13. * 此处为高地地图web服务的key
  14. ****************/
  15. webKey: 'b6a7f5b5e8bb76a100f3964056810a53',
  16. //出行方案
  17. navType: [
  18. { icon: "../../images/gdmap/type-1.png", name: "驾车", url: "https://restapi.amap.com/v3/direction/driving" },
  19. { icon: "../../images/gdmap/type-2.png", name: "公交", url: "https://restapi.amap.com/v3/direction/transit/integrated" },
  20. // { icon: "../../images/gdmap/type-3.png", name: "骑行", url: "https://restapi.amap.com/v4/direction/bicycling" },
  21. // { icon: "../../images/gdmap/type-4.png", name: "步行", url: "https://restapi.amap.com/v3/direction/walking" }
  22. ],
  23. //格式化距离
  24. distance: function (dis) {
  25. return dis < 1000 ? dis + "米" : (dis / 1000).toFixed(2).toString() + "公里";
  26. },
  27. //格式化时间
  28. resultFormat: function (result) {
  29. var h = Math.floor(result / 3600 % 24);
  30. var m = Math.floor(result / 60 % 60);
  31. if (h < 1) {
  32. return result = m + "分钟";
  33. } else {
  34. return result = h + "小时" + m + "分钟";
  35. }
  36. },
  37. //驾车,骑行,步行线路
  38. polyline: function (data) {
  39. var points = [];
  40. if (data.paths && data.paths[0] && data.paths[0].steps) {
  41. var steps = data.paths[0].steps;
  42. for (var i = 0; i < steps.length; i++) {
  43. var poLen = steps[i].polyline.split(';');
  44. for (var j = 0; j < poLen.length; j++) {
  45. points.push({
  46. longitude: parseFloat(poLen[j].split(',')[0]),
  47. latitude: parseFloat(poLen[j].split(',')[1])
  48. })
  49. }
  50. }
  51. }
  52. return points;
  53. },
  54. //弹窗
  55. dialog: function (content, callback) {
  56. wx.showModal({
  57. title: '提示',
  58. content: content,
  59. showCancel: false,
  60. success: function (res) {
  61. if (res.confirm) {
  62. if (callback) {
  63. callback();
  64. }
  65. }
  66. }
  67. })
  68. },
  69. //授权地理位置
  70. getLocation: function (callback) {
  71. wx.getLocation({
  72. type: 'gcj02',
  73. success: function () {
  74. if (callback) {
  75. callback();
  76. }
  77. },
  78. fail: function () {
  79. wx.getSetting({
  80. success: function (res) {
  81. if (!res.authSetting['scope.userInfo'] || !res.authSetting['scope.userLocation']) {
  82. wx.openSetting();
  83. }
  84. }
  85. });
  86. }
  87. })
  88. }
  89. }