// 文档地址 https://lbs.qq.com/service/webService/webServiceGuide/search/webServiceSearch // 注意当前请求仅打包后有效 import request from '@/utils/request' import { ref } from "vue" import { jsonp } from "@/utils/common.js" import config from '@/config.js' // 关键词不全 const httpUrl = "https://apis.map.qq.com/ws/place/v1/search" const Key = config.mapKey export function useCustomMap() { // 关键字 范围 页码 数量 成功回调 失败回调 function getPositionSearchByKeyword(keyword, boundary, successFun, errorFun, options) { let cpage = options.page || 1; let csize = options.size || 20; let cboundary = boundary; //'nearby(39.992870,116.310250,1000)' uni.showLoading({ title: '加载中' }) // #ifdef H5 jsonp(httpUrl, { key: Key, output: "jsonp", keyword: keyword, boundary: cboundary, page_size: csize, page_index: cpage, }).then(res => { successFun && successFun(res) }).catch(err => { errorFun && errorFun(err); }).finally(() => { uni.hideLoading(); }) // #endif // #ifdef APP uni.request({ url: httpUrl, method: 'get', data: { key: Key, output: "JSON", keyword: keyword, boundary: cboundary, page_size: csize, page_index: cpage, }, timeout: 20000, }).then(res => { successFun && successFun(res) }).catch(err => { console.log('err') errorFun && errorFun(err); }).finally(() => { uni.hideLoading(); }) // #endif } return { getPositionSearchByKeyword } }