/**
* 地址解析(地址转坐标)
* @param {String} address
* @link https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder
*/
export const getAddressLocation = (address)=>{
return new Promise((resolve, reject) => {
let config = wx.getStorageSync('GLOBAL_DATA');
if(!config) reject();
//#ifdef H5
//#endif
wx.request({
url: `https://apis.map.qq.com/ws/geocoder/v1/`,
data: {
key: config.tx_map_key,
address: address,
},
success:(res)=>{
if (!res.data) reject();
resolve(res.data.result);
},
fail:(err)=>{
reject();
}
})
})
}
/**
* 逆地址解析(坐标位置描述)
* @param {Object} fromLatlng
* @param {Object} poi_options
* @link https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder
*/
export const getLocationAddress = (fromLatlng, poi_options)=>{
poi_options = poi_options || "address_format=short;policy=5";
return new Promise((resolve, reject) => {
let config = wx.getStorageSync('GLOBAL_DATA');
if(!config) reject();
//#ifdef H5
//#endif
wx.request({
url: `https://apis.map.qq.com/ws/geocoder/v1/`,
data: {
location: fromLatlng,
get_poi: 1,
poi_options: poi_options,
key: config.tx_map_key
},
success:(res)=>{
console.log(res)
if (!res.data) reject();
resolve(res.data.result);
},
fail:(err)=>{
reject();
}
})
})
}
参数是地址字符串如:广东省广州市天河区岑村小学公交站,config.tx_map_key 配置一般在后端配置(根据业务),config.tx_map_key 申请到腾讯开发者后台添加