useMap.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. import {
  8. jsonp
  9. } from "@/utils/common.js"
  10. import config from '@/config.js'
  11. // 关键词不全
  12. const httpUrl = "https://apis.map.qq.com/ws/place/v1/search"
  13. const Key = config.mapKey
  14. export function useCustomMap() {
  15. // 关键字 范围 页码 数量 成功回调 失败回调
  16. function getPositionSearchByKeyword(keyword, boundary, successFun, errorFun, options) {
  17. let cpage = options.page || 1;
  18. let csize = options.size || 20;
  19. let cboundary = boundary; //'nearby(39.992870,116.310250,1000)'
  20. uni.showLoading({
  21. title: '加载中'
  22. })
  23. // #ifdef H5
  24. jsonp(httpUrl, {
  25. key: Key,
  26. output: "jsonp",
  27. keyword: keyword,
  28. boundary: cboundary,
  29. page_size: csize,
  30. page_index: cpage,
  31. }).then(res => {
  32. successFun && successFun(res)
  33. }).catch(err => {
  34. errorFun && errorFun(err);
  35. }).finally(() => {
  36. uni.hideLoading();
  37. })
  38. // #endif
  39. // #ifdef APP
  40. uni.request({
  41. url: httpUrl,
  42. method: 'get',
  43. data: {
  44. key: Key,
  45. output: "JSON",
  46. keyword: keyword,
  47. boundary: cboundary,
  48. page_size: csize,
  49. page_index: cpage,
  50. },
  51. timeout: 20000,
  52. }).then(res => {
  53. successFun && successFun(res)
  54. }).catch(err => {
  55. console.log('err')
  56. errorFun && errorFun(err);
  57. }).finally(() => {
  58. uni.hideLoading();
  59. })
  60. // #endif
  61. }
  62. return {
  63. getPositionSearchByKeyword
  64. }
  65. }