useMap.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // 文档地址 https://lbs.qq.com/service/webService/webServiceGuide/search/webServiceSearch
  2. // 注意当前请求仅打包后有效
  3. import request from '@/utils/request'
  4. import {
  5. ref
  6. } from "vue"
  7. // 关键词不全
  8. const httpUrl = "https://apis.map.qq.com/ws/place/v1/search"
  9. const Key = `KBYBZ-FS3KZ-U2FXR-7VPDX-L7J46-23F55`
  10. export function useCustomMap() {
  11. // 关键字 范围 页码 数量 成功回调 失败回调
  12. function getPositionSearchByKeyword(keyword, boundary, successFun, errorFun, options) {
  13. let cpage = options.page || 1;
  14. let csize = options.size || 20;
  15. let cboundary = boundary; //'nearby(39.992870,116.310250,1000)'
  16. uni.showLoading({
  17. title: '加载中'
  18. })
  19. uni.request({
  20. url: httpUrl,
  21. method: 'get',
  22. data: {
  23. key: Key,
  24. output: "json",
  25. keyword: keyword,
  26. boundary: cboundary,
  27. page_size: csize,
  28. page_index: cpage,
  29. },
  30. timeout: 20000,
  31. }).then(res => {
  32. successFun && successFun(res)
  33. }).catch(err => {
  34. console.log('err')
  35. errorFun && errorFun(err);
  36. }).finally(() => {
  37. uni.hideLoading();
  38. })
  39. }
  40. return {
  41. getPositionSearchByKeyword
  42. }
  43. }