// pages/card_info/card_info.js
var config = require("../../config.js");
var util = require("../../utils/utils.js");
var city = require('../../utils/city.js');
var app = getApp();
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
//[官网下载sdk](https://lbs.qq.com/qqmap_wx_jssdk/index.html)
// 实例化API核心类
var qqmapsdk = new QQMapWX({
key: app.globalData.map_key // 必填
});
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
var that = this
that.getCurrentLocal()
},
// 获取当前地理位置 授权验证
getCurrentLocal() {
let that = this;
wx.getSetting({
success(res) {
if (res.authSetting['scope.userLocation'] == false) { // 如果已拒绝授权,则打开设置页面
wx.openSetting({
success(res) {
console.log(res)
}
})
} else { // 第一次授权,或者已授权,直接调用相关api
wx.getLocation({
type: 'wgs84',
success(res) {
var param = {
location: res.latitude + ',' + res.longitude,
key: app.globalData.map_key,
get_poi: 1
}
//下面是get去请求数据
var url = config.qqMapApi
// https://apis.map.qq.com/ws/geocoder/v1/
util.postrequest(url, param, function (res) {
var d = res.data.result
console.log(d)
console.log(d.address_component.city)
that.setData({
citySelected: d.address_component.city,
})
})
}
})
}
}
})
},
//get方法
//get方法
function getrequest(url, data, cb) {
wx.request({
// https://apis.map.qq.com/ws/geocoder/v1/
url: url,
method: 'GET',
header: {
'content-type': 'application/json'
},
data: data,
success: function (res) {
return typeof 'function' && cb(res)
},
fail: function (res) {
wx.showToast({
title: '网络请求失败,稍后再试',
icon: 'none',
duration: 2000,
})
},
complete: function (res) {
}
})
}
//调起地图选点
//调起腾讯地图选点
getMapad: function() {
var t = this;
wx.getSetting({
success(res) {
if (res.authSetting['scope.userLocation'] == false) { // 如果已拒绝授权,则打开设置页面
wx.openSetting({
success(res) {
console.log(res)
}
})
} else {
wx.chooseLocation({
success: function(e) {
console.log(e)
t.setData({
// now_location_name: e.address,
// now_location_lat: e.latitude,
// now_location_lng: e.longitude,
// now_detail_address: e.name
});
},
fail: function(t) {console.log(t)},
complete: function(t) {console.log(t)}
});
}
}
})
}
03-19
372
03-07
385
12-20
454
12-15
96
12-15
119
12-15
227
12-15
105
07-12
1247
05-12
417
博客
二维数组根据某个字段排序
02-15
250
12-26
323
11-24
503