3,143
社区成员
发帖
与我相关
我的任务
分享
//微信初始化完成
function wxInit() {
if (cityname == null || cityname == "" || cityname == "广西") {
wx.getLocation({//获取本地经纬度
type : 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,腾讯、google、高德坐标,可传入'gcj02'
success : function(res) {
lat = res.latitude; // 纬度,浮点数,范围为90 ~ -90
lon = res.longitude; // 经度,浮点数,范围为180 ~ -180。
//5 [默认]腾讯、google、高德坐标
getQQCity("5");
},
fail : function(res) {
//alert('用户拒绝授权获取地理位置');
//initRedList();
}
});
wx.checkJsApi({
jsApiList : [ 'getLocation' ], // 需要检测的JS接口列表,所有JS接口列表见附录2,
success : function(res) {
if (res.checkResult.getLocation == "true"
|| res.checkResult.getLocation == true) {
} else {
//initRedList();
alert("定位失败请检查微信应用设置");
}
}
});
}
}
function getQQCity(coord_type) {
if (lon == "" || lat == "") {
//initRedList();
return;
}
var fn = function(data) {
var isCity2 = 0;
if (data.status == 0) {
//alert(coord_type+"反查地址:"+data.result.address);
//cityname = data.result.address_component.city.replace("市","");
cityname = data.result.address_component.city.substring(0,
2);
var iscity = 0;
for (var i = 0; i < cityList.length; i++) {
if (cityList[i].CITYNAME == cityname) {
cityCode = cityList[i].CITYCODE;
isCity2 = 1;
}
}
if (isCity2 == 0) {
lat = "";
lon = "";
cityname = "广西";
cityCode = "0590";
location.hash = "";
}
$("#js-cityname").text(cityname);
}
if (isCity2 == 1) {
currentPage = 0;
everyPage = 5;
$('.in_probox ul').empty();
initRedList();
batch_id = "0";
initSecKill();
initRecommend();
}
};
var ef = function errinit() {
//initRedList();
};
var url = "https://apis.map.qq.com/ws/geocoder/v1/";
var maps = {
output : "jsonp",
"location" : lat + "," + lon,
"coord_type" : coord_type,
"key" : "M3JBZ-7ATWX-RIB4V-ZO5U2-HWZI2-VBBTE"
};
ajaxTimeout(url, maps, fn, ef, 3000);
}
function ajaxTimeout(url, maps, fn, ef, time) {
var ajaxTimeoutTest = $.ajax({
url : url, //请求的URL
timeout : time, //超时时间设置,单位毫秒
type : 'post', //请求方式,get或post
data : maps, //请求所传参数,json格式
dataType : 'jsonp',//返回的数据格式
jsonp : 'callback',
success : fn,
error : ef,
complete : function(XMLHttpRequest, status) { //请求完成后最终执行参数
if (status == 'timeout') {//超时,status还有success,error等值的情况
ajaxTimeoutTest.abort();
ef();
}
}
});
}