tianditu.js 988 B

1234567891011121314151617181920212223242526272829303132
  1. /* 文档 http://lbs.tianditu.gov.cn/server/search2.html */
  2. class tianditu {
  3. /* 逆解析 */
  4. getPlace(lon, lat) {
  5. return this.request(`/geocoder?postStr={'lon':${lon},'lat':${lat},'ver':1}&type=geocode`)
  6. }
  7. /* 地名搜索 */
  8. placeNameSearch(data = {}) {
  9. return this.request(`/v2/search?postStr=${JSON.stringify(data)}&type=query`)
  10. }
  11. request(query, method = 'GET') {
  12. const tks = ['524ebc3954aaa26259f80ea937a3f569', '8aad97b24c38ed6643207de9da174b98', '47bb2ca36a43839fd7c45e2d762561f8'],
  13. url = 'https://api.tianditu.gov.cn' + query + `&tk=${tks[ Math.floor(Math.random() * tks.length)]}`
  14. return new Promise((resolve, reject) => {
  15. this._request(url, method, resolve)
  16. })
  17. }
  18. _request(url, method, resolve) {
  19. uni.request({
  20. url,
  21. method,
  22. success: (res) => {
  23. resolve(res.data)
  24. }
  25. });
  26. }
  27. }
  28. export {
  29. tianditu
  30. }