pull/23/head
chargehand 2 years ago
parent c8d99f0836
commit 872710dc11

@ -1,77 +0,0 @@
// map.js
let schoolData = require('../../resources/gis-school')
Page({
data: {
centerX:113.3245211,
centerY:23.10229,
markers: [],
controls: [{
id: 1,
iconPath: '/image/location-control.png',
position: {
left: 0,
top:10,
width: 40,
height: 40
},
clickable: true
}]
},
onReady: function (e) {
// 使用 wx.createMapContext 获取 map 上下文
this.mapCtx = wx.createMapContext('myMap')
},
onLoad: function () {
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=this.createMarker(res);
this.setData({
centerX:longitude,
centerY:latitude,
markers:this.getSchoolMarkers()
})
}
});
},
regionchange(e) {
console.log(e.type)
},
markertap(e) {
console.log(e)
},
controltap(e) {
console.log(e.controlId)
this.moveToLocation()
},
getSchoolMarkers(){
let markers=[];
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: "/image/location.png",
id:point.id || 0,
name:point.name || '',
latitude: latitude,
longitude: longitude,
width: 25,
height: 48
};
return marker;
}
})

@ -1 +0,0 @@
<map id="map" scale="5" controls="{{controls}}" bindcontroltap="controltap" markers="{{markers}}" bindmarkertap="markertap" bindregionchange="regionchange" show-location style="width: 100%; height: 580px;"></map>

@ -25,7 +25,10 @@
"pages/index_hjf/index_hjf",
"pages/index1/index1",
"pages/adlogin/adlogin",
"pages/login_1/login_1"
"pages/login_1/login_1",
"pages/getWeather/getWeather",
"pages/map/map"
],
"window": {
"backgroundColor": "#F6F6F6",
@ -40,15 +43,10 @@
"borderStyle": "black",
"backgroundColor": "#ffffff",
"list": [{
"pagePath": "pages/location/location",
"pagePath": "pages/map/map",
"iconPath": "image/wechat.png",
"selectedIconPath": "image/locate.png",
"text": "导航"
},{
"pagePath": "pages/Find directions/Find directions",
"iconPath": "image/map.png",
"selectedIconPath": "image/map_active.png",
"text": "查询路线"
},{
"pagePath": "pages/text/text",
"iconPath": "image/locate.png",
@ -58,6 +56,14 @@
]
},
"debug": true,
"style": "v2",
"sitemapLocation": "sitemap.json",
"style": "v2"
"requiredPrivateInfos":[
"getLocation"
],
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -0,0 +1,36 @@
var amapFile = require('../../utils/amap-wx.js');
var app = getApp();
Page({
data: {
city:"天津",
weather:"晴",
temperature:"10",
windpower:"18级",
winddirection:"南",
humidity:"5",
},
onLoad: function(options){
var that = this;
var myAmapFun = new amapFile.AMapWX({key:'78a99442f6e5cad3bfb832e33bdcf629'});
myAmapFun.getWeather({
success: function(res){
//成功回调
console.log("调取天气接口成功", res)
// 一定要在接口里进行赋值,否则接口数据还未返回,页面就已经将数据取走进行显示
that.setData({
city: res.city.data,
weather: res.weather.data,
temperature: res.temperature.data,
windpower: res.windpower.data,
winddirection: res.winddirection.data,
humidity: res.humidity.data
})
},
fail: function(info){
//失败回调
console.log(info)
}
})
}
})

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save