map组件在使用定点的时候,我在后端获取到 经纬度,在开发者工具上可以显示 定点。 但是在 手机上就不显示定点了,这个怎么处理
const App = getApp()
Page({
data: {
centerX: '',
centerY: '',
markers: [],
ddd:''
},
onReady: function (e) {
// 使用 wx.createMapContext 获取 map 上下文
this.mapCtx = wx.createMapContext('myMap')
},
onLoad: function () {
this.getlist()
console.log('地图定位!')
let that = this
// 获取自己的位置
wx.getLocation({
type: 'gcj02', //返回可以用于wx.openLocation的经纬度
success: (res) => {
console.log(res)
let latitude = res.latitude;
let longitude = res.longitude;
let marker = that.createMarker(res);
that.setData({
centerX: longitude,
centerY: latitude,
markers: that.getSchoolMarkers()
})
}
});
},
getlist(){
var _this=this
App._get('data_service/gis', {}, function (res) {
console.log(res)
_this.setData({
ddd: res
})
});
},
getSchoolMarkers() {
let markers = [];
var schoolData= this.data.ddd
for (let item of schoolData) {
let marker = this.createMarker(item);
markers.push(marker)
}
return markers;
},
moveToLocation: function () {
this.mapCtx.moveToLocation()
},
createMarker(point) {
let latitude = point.latitude;
let longitude = point.longitude;
let marker = {
iconPath: "../../images/map/map.png",
id: point.id || 0,
name: point.siteName || '',
latitude: latitude,
longitude: longitude,
water: point.waterLevel || '--',
width: 25,
height: 48,
customCallout:{
display: 'BYCLICK',
anchorX: 0,//横向偏移
anchorY: 0,
}
};
return marker;
},
// 移动地图时触发
regionchange(e) {
console.log(e.type)
},
// 点击标记点时触发
markertap(e) {
console.log(e, e.markerId);
var data = this.data.ddd;
},
// 点击控件时触发
controltap(e) {
console.log(e.controlId)
this.moveToLocation()
},
})