getLocation.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // wx.config({
  2. // debug: true,
  3. // appId: 'wxa3991865de920847',
  4. // timestamp: 1583378561,
  5. // nonceStr: '<?php echo $signPackage["nonceStr"]; ?>',
  6. // signature: '7c909d41d5f99a35fd9d39c179dae233b001678d',
  7. // jsApiList: [
  8. // // 所有要调用的 API 都要加到这个列表中
  9. // 'getLocation',
  10. // ]
  11. // });
  12. function getLocation() {
  13. return;
  14. wx.getLocation({
  15. type: 'wgs84',
  16. success: function (res) {
  17. // alert(JSON.stringify(res));
  18. var geocoder = new qq.maps.Geocoder({
  19. complete: function (result) {
  20. if ('当阳市' === result.detail.addressComponents.district) {
  21. autoLocal = '当阳市';
  22. } else {
  23. autoLocal = result.detail.addressComponents.city;
  24. }
  25. autoAddr = result.detail.address;
  26. // alert(result.detail.address)
  27. console.log(result);
  28. }
  29. })
  30. var coord = new qq.maps.LatLng(res.latitude, res.longitude)
  31. geocoder.getAddress(coord)
  32. },
  33. cancel: function (res) {
  34. alert('用户拒绝授权获取地理位置');
  35. }
  36. });
  37. }