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. wx.getLocation({
  14. type: 'wgs84',
  15. success: function (res) {
  16. // alert(JSON.stringify(res));
  17. var geocoder = new qq.maps.Geocoder({
  18. complete: function (result) {
  19. if ('当阳市' === result.detail.addressComponents.district) {
  20. autoLocal='当阳市';
  21. } else {
  22. autoLocal = result.detail.addressComponents.city;
  23. }
  24. autoAddr = result.detail.address;
  25. // alert(result.detail.address)
  26. console.log(result);
  27. }
  28. })
  29. var coord = new qq.maps.LatLng(res.latitude, res.longitude)
  30. geocoder.getAddress(coord)
  31. },
  32. cancel: function (res) {
  33. alert('用户拒绝授权获取地理位置');
  34. }
  35. });
  36. }