location.js 847 B

12345678910111213141516171819202122232425262728293031323334
  1. const QQMapWX = require("./qqmap-wx-jssdk.min.js")
  2. module.exports = {
  3. getLocation: function(cb){
  4. wx.getLocation({
  5. type: 'wgs84',
  6. success: function (res) {
  7. let location = {
  8. latitude: res.latitude,
  9. longitude: res.longitude
  10. };
  11. cb&&cb( location )
  12. },
  13. fail: function( res ){
  14. cb && cb( {latitude:39.90 , longitude: 116.47})
  15. }
  16. })
  17. },
  18. getAddress: function(location, cb ){
  19. qqmapsdk = new QQMapWX({
  20. key: 'YESBZ-R54RO-R34W7-SOMH4-RTMFE-VOBRK'
  21. });
  22. qqmapsdk.reverseGeocoder({
  23. location:location,
  24. success: function (result) {
  25. location.city = result.result.address_component.city;
  26. location.address = result.result.address;
  27. cb&&cb( location );
  28. }
  29. })
  30. }
  31. }