loc-amap删除.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Tools from './tools.js';
  2. const amapFile = require('@/common/amap-wx.js')
  3. var myAmapFun = new amapFile.AMapWX({key: '01d42bb16e23baca11f1227164a200fd'}); //01d42bb16e23baca11f1227164a200fd使用本人高德
  4. //逆向解析
  5. function getNameByLatLng(latitude,longitude){
  6. return new Promise((resolve,reject)=>{
  7. //未使用微信授权api
  8. myAmapFun.getRegeo({
  9. location:longitude+','+latitude,
  10. success: function(data){
  11. // console.log("getRegeo data--",data);
  12. resolve(data[0]);
  13. },
  14. fail: err=> {
  15. reject("逆向地址解析错误");
  16. console.log(err)
  17. }
  18. })
  19. })
  20. }
  21. async function chooseLoc(){
  22. return new Promise(async (resolve,reject)=>{
  23. let [cErr,cRes] = await uni.chooseLocation({type:'gcj02'});
  24. if(cErr){
  25. reject(cErr)
  26. return;
  27. }
  28. let {latitude,longitude} = cRes
  29. let loc = await getNameByLatLng(latitude,longitude) || {};
  30. // console.log('getNameByLatLng===',loc,loc.regeocodeData.addressComponent.province);
  31. if(loc.regeocodeData && loc.regeocodeData.addressComponent){
  32. let {province,city,district,township} = loc.regeocodeData.addressComponent;
  33. let address = district+township+loc.desc;
  34. resolve({
  35. province,
  36. city,
  37. area:district,
  38. address,
  39. latitude,
  40. longitude,
  41. })
  42. return;
  43. }
  44. return reject(false);
  45. })
  46. }
  47. export{
  48. getNameByLatLng,
  49. chooseLoc,
  50. }