/**
* @file 微信小程序JSAPI
* @author 崔健 [email protected] 2017.01.10
*/
/**
* 百度地图微信小程序API类
*
* @class
*/
class BMapWX {
/**
* 百度地图微信小程序API类
*
* @constructor
*/
constructor(param) {
this.ak = param["ak"];
}
/**
* 使用微信接口进行定位
*
* @param {string} type 坐标类型
* @param {Function} success 成功执行
* @param {Function} fail 失败执行
* @param {Function} complete 完成后执行
*/
getWXLocation(type, success, fail, complete) {
type = type || 'gcj02',
success = success || function () {};
fail = fail || function () {};
complete = complete || function () {};
wx.getLocation({
type: type,
success: success,
fail: fail,
complete:complete
});
}
/**
* POI周边检索
*
* @param {Object} param 检索配置
* 参数对象结构可以参考
* http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-placeapi
*/
search(param) {
var that = this;
param = param || {};
let searchparam = {
query: param["query"] || '生活服务$美食&酒店',
scope: param["scope"] || 1,
filter: param["filter"] || '',
coord_type: param["coord_type"] || 2,
page_size: param["page_size"] || 10,
page_num: param["page_num"] || 0,
output: param["output"] || 'json',
ak: that.ak,
sn: param["sn"] || '',
timestamp: param["timestamp"] || '',
radius: param["radius"] || 2000,
ret_coordtype: 'gcj02ll'
};
let otherparam = {
iconPath: param["iconPath"],
iconTapPath: param["iconTapPath"],
width: param["width"],
height: param["height"],
alpha: param["alpha"] || 1,
success: param["success"] || function () {},
fail: param["fail"] || function () {}
};
let type = 'gcj02';
let locationsuccess = function (result) {
searchparam["location"] = result["latitude"] + ',' + result["longitude"];
wx.request({
url: 'https://api.map.baidu.com/place/v2/search',
data: searchparam,
header: {
"content-type": "application/json"
},
method: 'GET',
success(data) {
let res = data["data"];
if (res["status"] === 0) {
let poiArr = res["results"];
// outputRes 包含两个对象,
// originalData为百度接口返回的原始数据
// wxMarkerData为小程序规范的marker格式
let outputRes = {};
outputRes["originalData"] = res;
outputRes["wxMarkerData"] = [];
for (let i = 0; i < poiArr.length; i++) {
outputRes["wxMarkerData"][i] = {
id: i,
latitude: poiArr[i]["location"]["lat"],
longitude: poiArr[i]["location"]["lng"],
title: poiArr[i]["name"],
iconPath: otherparam["iconPath"],
iconTapPath: otherparam["iconTapPath"],
address: poiArr[i]["address"],
telephone: poiArr[i]["telephone"],
alpha: otherparam["alpha"],
width: otherparam["width"],
height: otherparam["height"]
}
}
otherparam.success(outputRes);
} else {
otherparam.fail({
errMsg: res["message"],
statusCode: res["status"]
});
}
},
fail(data) {
otherparam.fail(data);
}
});
}
let locationfail = function (result) {
otherparam.fail(result);
};
let locationcomplete = function (result) {
};
if (!param["location"]) {
that.getWXLocation(type, locationsuccess, locationfail, locationcomplete);
} else {
let longitude = param.location.split(',')[1];
let latitude = param.location.split(',')[0];
let errMsg = 'input location';
let res = {
errMsg: errMsg,
latitude: latitude,
longitude: longitude
};
locationsuccess(res);
}
}
/**
* sug模糊检索
*
* @param {Object} param 检索配置
* 参数对象结构可以参考
* http://lbsyun.baidu.com/index.php?title=webapi/place-suggestion-api
*/
suggestion(param) {
var that = this;
param = param || {};
let suggestionparam = {
query: param["query"] || '',
region: param["region"] || '全国',
city_limit: param["city_limit"] || false,
output: param["output"] || 'json',
ak: that.ak,
sn: param["sn"] || '',
timestamp: param["timestamp"] || '',
ret_coordtype: 'gcj02ll'
};
let otherparam = {
success: param["success"] || function () {},
fail: param["fail"] || function () {}
};
wx.request({
url: 'https://api.map.baidu.com/place/v2/suggestion',
data: suggestionparam,
header: {
"content-type": "application/json"
},
method: 'GET',
success(data) {
let res = data["data"];
if (res["status"] === 0) {
otherparam.success(res);
} else {
otherparam.fail({
errMsg: res["message"],
statusCode: res["status"]
});
}
},
fail(data) {
otherparam.fail(data);
}
});
}
/**
* rgc检索(坐标->地点描述)
*
* @param {Object} param 检索配置
* 参数对象结构可以参考
* http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding
*/
regeocoding(param) {
var that = this;
param = param || {};
let regeocodingparam = {
coordtype: param["coordtype"] || 'gcj02ll',
pois: param["pois"] || 0,
output: param["output"] || 'json',
ak: that.ak,
sn: param["sn"] || '',
timestamp: param["timestamp"] || '',
ret_coordtype: 'gcj02ll'
};
let otherparam = {
iconPath: param["iconPath"],
iconTapPath: param["iconTapPath"],
width: param["width"],
height: param["height"],
alpha: param["alpha"] || 1,
success: param["success"] || function () {},
fail: param["fail"] || function () {}
};
let type = 'gcj02';
let locationsuccess = function (result) {
regeocodingparam["location"] = result["latitude"] + ',' + result["longitude"];
wx.request({
url: 'https://api.map.baidu.com/geocoder/v2/',
data: regeocodingparam,
header: {
"content-type": "application/json"
},
method: 'GET',
success(data) {
let res = da
没有合适的资源?快使用搜索试试~ 我知道了~
天气预报.zip小程序例子源码打包下载适合研究学习技术
共114个文件
png:49个
js:23个
wxml:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 183 浏览量
2022-03-13
03:03:51
上传
评论
收藏 1.57MB ZIP 举报
温馨提示
天气预报.zip小程序例子源码打包下载适合研究学习技术天气预报.zip小程序例子源码打包下载适合研究学习技术 1.适合学习做毕业设计参考模板。 2.适合程序员学习开发小程序研究用 3.适合小公司换皮做新项目参考使用用
资源推荐
资源详情
资源评论
收起资源包目录
天气预报.zip小程序例子源码打包下载适合研究学习技术 (114个子文件)
.gitattributes 378B
.gitignore 649B
menu-img.jpg 92KB
bg1.jpg 80KB
bg2.jpg 45KB
bg.jpg 12KB
bg.jpg 12KB
bmap-wx.js 13KB
calc.js 8KB
game_manager.js 6KB
bmap-wx.min.js 5KB
main.js 4KB
2048.js 3KB
weather.js 3KB
main.js 3KB
grid.js 2KB
life.js 2KB
future.js 2KB
util.js 1KB
xiaomi.js 841B
app.js 719B
app.js 719B
app.js 719B
tile.js 711B
index.js 658B
tools.js 468B
util.js 460B
util.js 460B
util.js 460B
local_storage_manager.js 74B
app.json 986B
app.json 340B
app.json 216B
2048.json 120B
jsconfig.json 55B
jsconfig.json 55B
weather.json 48B
index.json 2B
xiaomi.json 2B
2.png 266KB
1.png 233KB
3.png 222KB
32.png 25KB
29.png 22KB
28.png 21KB
17.png 20KB
26.png 20KB
18.png 20KB
27.png 20KB
25.png 19KB
31.png 19KB
6.png 19KB
5.png 19KB
13.png 19KB
24.png 18KB
16.png 18KB
23.png 18KB
12.png 18KB
7.png 18KB
14.png 17KB
22.png 17KB
11.png 17KB
33.png 17KB
20.png 16KB
10.png 16KB
4.png 16KB
15.png 16KB
21.png 16KB
2.png 15KB
9.png 15KB
3.png 15KB
8.png 14KB
1.png 13KB
19.png 12KB
30.png 9KB
car.png 8KB
sport.png 7KB
travel.png 5KB
uv.png 4KB
cloth.png 3KB
medicine.png 3KB
life-s.png 2KB
life.png 2KB
future-s.png 1KB
future.png 945B
map.png 820B
home-s.png 720B
home.png 678B
weapp.d.ts 42KB
weapp.d.ts 42KB
xiaomi.wxml 3KB
weather.wxml 2KB
index.wxml 2KB
2048.wxml 1KB
main.wxml 693B
main.wxml 574B
futuretpl.wxml 505B
itemtpl.wxml 421B
itemtpl.wxml 421B
life.wxml 335B
共 114 条
- 1
- 2
资源评论
yxkfw
- 粉丝: 76
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功