1. 程式人生 > >微信小程式 地圖示記

微信小程式 地圖示記

"/> .js Page({ /** * 頁面的初始資料 */ data: { longitude:[], latitude:[], markers:[] }, onLoad: function (options) { var that = this; // 獲取當前地理位置 wx.getLocation({ type: 'wgs84', success: function (res) { var latitude = res.latitude var longitude = res.longitude var
markers = new Array(); //資料庫讀取標記資訊 wx.request({ url: 'http://localhost/action.php',//請求地址 data: {}, header: {//請求頭 "Content-Type": "applciation/json" }, method: "get", success: function (res) { var data = res.data; //console.log(data)
for (var i = 0;i < data.length; i++) { var name = data[i].name; //名稱 var lat = data[i].latitude; //經度 var lon = data[i].longitude;//緯度 var info = { id : 0, iconPath: "/images/marker_red.png", latitude: ''
, longitude: '', width: 20, height: 25, title: "", }; info.id = i info.latitude = lat info.longitude = lon info.title = name markers.push(info); } var str = JSON.stringify(markers); console.log(markers); // console.log(latitude); //console.log(longitude); that.setData( { latitude: latitude, longitude: longitude, markers: markers } ) }, fail: function (err) { },//請求失敗 complete: function () { }//請求完成後執行的函式 }) } }) } )}