map.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="main">
  3. <!-- <iframe
  4. :src="'https://apis.map.qq.com/uri/v1/marker?marker=coord:'+location.latitude+','+location.longitude+';title:'++';addr:'+info.title+'&referer='"
  5. frameborder="0"></iframe> -->
  6. <map v-if="location.latitude" class="qq-map" id="map" :markers="markers" :subkey="mapKey"
  7. :longitude="location.longitude" :latitude="location.latitude" scale="14" :polyline="polyline"
  8. layer-style="style1"></map>
  9. <tabbar :index="type"></tabbar>
  10. </view>
  11. </template>
  12. <script>
  13. import tabbar from '../../components/tabbar.vue'
  14. var QQMapWX = require('../../common/qqmap-wx-jssdk.min.js');
  15. var qqmapsdk;
  16. export default {
  17. components: {
  18. tabbar
  19. },
  20. data() {
  21. return {
  22. mapKey: '',
  23. markers: [],
  24. location: {
  25. longitude: '',
  26. latitude: ''
  27. },
  28. info: {
  29. title: ''
  30. },
  31. polyline: [],
  32. type: '1',
  33. }
  34. },
  35. onLoad(options) {
  36. var _this = this
  37. console.log(options)
  38. var latitude = typeof(options.latitude) != 'undefined' ? options.latitude : '';
  39. var longitude = typeof(options.longitude) != 'undefined' ? options.longitude : '';
  40. var location = typeof(options.location) != 'undefined' ? options.location : '';
  41. _this.type = typeof(options.type) != 'undefined' ? parseInt(options.type) : 1;
  42. _this.info.title = typeof(options.title) != 'undefined' ? options.title : '商家位置';
  43. _this.mapKey = _this.$request.mapKey
  44. //获取当前的地理位置、速度
  45. if (!location || !latitude || !longitude) {
  46. _this.$u.toast('参数错误');
  47. setTimeout(function() {
  48. uni.navigateBack({
  49. delta: '-1'
  50. })
  51. }, 800);
  52. return false;
  53. }
  54. // 获取定位
  55. uni.getLocation({
  56. type: 'wgs84', //腾讯地图使用gcj02获取位置坐标
  57. altitude: true,
  58. geocode: true,
  59. highAccuracyExpireTime: 100,
  60. success: function(res) {
  61. console.log('当前位置的经度:' + res.longitude);
  62. console.log('当前位置的纬度:' + res.latitude);
  63. res.expired = (new Date()).getTime() + 10000
  64. _this.location = res
  65. uni.setStorageSync('rrc.location', JSON.stringify(res))
  66. uni.openLocation({
  67. type: 'gcj02',
  68. latitude: parseFloat(latitude),
  69. longitude: parseFloat(longitude),
  70. name: _this.info.title,
  71. address: location,
  72. scale: 28
  73. })
  74. },
  75. fail: function(err) {
  76. uni.getSystemInfo({
  77. success(res) {
  78. // 安卓
  79. var plusObj = typeof(plus) != 'undefined' ? plus : ''
  80. if (res.platform == 'android' && plusObj) {
  81. var context = plus.android.importClass(
  82. 'android.content.Context');
  83. var locationManager = plus.android.importClass(
  84. 'android.location.LocationManager');
  85. var main = plus.android.runtimeMainActivity();
  86. var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
  87. if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
  88. uni.showModal({
  89. title: '提示',
  90. content: '请打开定位服务功能,并授权',
  91. showCancel: false,
  92. success(result) {
  93. if (result.confirm == true) {
  94. if (!mainSvr.isProviderEnabled(
  95. locationManager.GPS_PROVIDER
  96. )) {
  97. var Intent = plus.android
  98. .importClass(
  99. 'android.content.Intent');
  100. var Settings = plus.android
  101. .importClass(
  102. 'android.provider.Settings'
  103. );
  104. var newIntent = new Intent(Settings
  105. .ACTION_LOCATION_SOURCE_SETTINGS
  106. );
  107. main.startActivity(newIntent);
  108. }
  109. }
  110. }
  111. })
  112. }
  113. } else {
  114. _this.$u.toast('打开定位失败');
  115. }
  116. },
  117. fail() {
  118. _this.$u.toast('打开定位失败');
  119. }
  120. })
  121. console.log(err)
  122. }
  123. });
  124. },
  125. methods: {
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .map,
  131. .qq-map {
  132. width: 100%;
  133. height: 100%;
  134. }
  135. </style>