map.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. // 中心点纬度、经度
  10. latitude: "",
  11. longitude: "",
  12. // 标记点 当前位置
  13. markers: [],
  14. isShow: true,
  15. storeName: "",
  16. storeAddress: "",
  17. distance: ""
  18. },
  19. onLoad: function (options) {
  20. // 页面初始化 options为页面跳转所带来的参数
  21. this.mapCtx = wx.createMapContext('myMap');
  22. this.mapCtx.moveToLocation();
  23. let that = this;
  24. util.getLocation((lng, lat) => {
  25. util.request(api.NearbyList, { longitude: lng, latitude: lat }).then((res) => {
  26. let markers = [];
  27. let marker = {
  28. iconPath: "/static/images/myAddress.png",
  29. id: 0,
  30. latitude: lat,
  31. longitude: lng,
  32. width: 35,
  33. height: 35,
  34. clickable: true,
  35. };
  36. markers.push(marker);
  37. let nlist = res.data;
  38. for (var i = 1; i <= nlist.length; i++) {
  39. let marker = {
  40. iconPath: "/static/images/address.png",
  41. id: i,
  42. latitude: nlist[i-1].latitude,
  43. longitude: nlist[i-1].longitude,
  44. width: 35,
  45. height: 35,
  46. clickable: true
  47. };
  48. markers.push(marker);
  49. }
  50. that.setData({
  51. latitude: lat,
  52. longitude: lng,
  53. markers: markers
  54. })
  55. })
  56. })
  57. },
  58. onReady: function () {
  59. // 页面渲染完成
  60. wx.create
  61. },
  62. onShow: function () {
  63. // 页面显示
  64. },
  65. onHide: function () {
  66. // 页面隐藏
  67. },
  68. onUnload: function () {
  69. // 页面关闭
  70. }
  71. })