sosMap.nvue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view >
  3. <map :style="{width: windowWidth+'px', height: windowHeight+'px'}" :latitude="latitude" :longitude="longitude" :markers="covers"></map>
  4. <view class="footer">
  5. <view class="infobox">
  6. <view style="flex: 1;">
  7. <view class="infobox-title">
  8. <image class="address_icon" src="@/static/images/pages_watch/icons/address_icon.png" mode="aspectFill"></image>
  9. <text class="text">{{dateTime.substring(5,16)}} 手表端发起紧急呼救{{windowHeight}}</text>
  10. </view>
  11. <text class="text">{{address}}</text>
  12. </view>
  13. <image class="location" src="@/static/images/pages_watch/icons/location2.png" mode="aspectFill" @click="handleMap()"></image>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import { getAddressByLocation } from "@/api/pages_watch/common.js";
  20. export default {
  21. data() {
  22. return {
  23. windowWidth: uni.getSystemInfoSync().windowWidth,
  24. windowHeight: uni.getSystemInfoSync().windowHeight,
  25. platform:uni.getSystemInfoSync().platform,
  26. location: '116.39742,39.909', // 经度,纬度
  27. address: '',
  28. dateTime: '',
  29. latitude: 39.909, // 纬度
  30. longitude: 116.39742, // 经度
  31. covers: [{
  32. id: 1,
  33. latitude: 39.909,
  34. longitude: 116.39742,
  35. iconPath: '/static/images/pages_watch/icons/location.png',
  36. width: '50', // 标记点图标宽度
  37. height: '50' // 标记点图标高度
  38. }]
  39. }
  40. },
  41. onLoad(option) {
  42. this.location = option.location || '116.39742,39.909'
  43. this.latitude = this.location.split(',')[1]
  44. this.longitude = this.location.split(',')[0]
  45. this.covers[0].latitude = this.latitude
  46. this.covers[0].longitude = this.longitude
  47. this.dateTime = option.dateTime || ''
  48. this.getAddress()
  49. },
  50. methods: {
  51. getAddress() {
  52. getAddressByLocation({location: this.location}).then(res=>{
  53. this.address = res.msg
  54. })
  55. },
  56. handleMap() {
  57. // #ifdef APP
  58. this.toMapAPP(this.location)
  59. // #endif
  60. // #ifdef MP-WEIXIN
  61. uni.openLocation({
  62. latitude: Number(this.latitude),
  63. longitude: Number(this.longitude),
  64. name: this.address,
  65. success: function () {
  66. console.log('success');
  67. },
  68. complete:(res)=> {
  69. console.log('complete',res);
  70. }
  71. });
  72. // #endif
  73. },
  74. //打开第三方地图
  75. toMapAPP(){
  76. let latitude = this.latitude
  77. let longitude = this.longitude
  78. let name = this.address
  79. let url = "";
  80. if (plus.os.name == "Android") {//判断是安卓端
  81. plus.nativeUI.actionSheet({//选择菜单
  82. title: "选择地图应用",
  83. cancel: "取消",
  84. buttons: [{title: "腾讯地图"},{title: "百度地图"}, {title: "高德地图"}]
  85. }, function(item) {
  86. let tit = ''
  87. switch (item.index) {
  88. //下面是拼接url,不同系统以及不同地图都有不同的拼接字段
  89. case 1:
  90. //注意referer=xxx的xxx替换成你在腾讯地图开发平台申请的key
  91. tit = '腾讯地图'
  92. url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
  93. break;
  94. case 2:
  95. tit = '百度地图'
  96. url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&coord_type=gcj02&src=andr.baidu.openAPIdemo`;
  97. break;
  98. case 3:
  99. tit = '高德地图'
  100. url = `androidamap://viewMap?sourceApplication=appname&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
  101. break;
  102. default:
  103. break;
  104. }
  105. if (url != "") {
  106. url = encodeURI(url);
  107. //plus.runtime.openURL(url,function(e){})调起手机APP应用
  108. plus.runtime.openURL(url, function(e) {
  109. // plus.nativeUI.alert("本机未安装指定的地图应用");
  110. uni.showToast({
  111. title: '未安装 ' + tit,
  112. icon: 'none'
  113. })
  114. });
  115. }
  116. })
  117. } else {
  118. // iOS上获取本机是否安装了百度高德地图,需要在manifest里配置
  119. // 在manifest.json文件app-plus->distribute->apple->urlschemewhitelist节点下添加
  120. //(如urlschemewhitelist:["iosamap","baidumap"])
  121. plus.nativeUI.actionSheet({
  122. title: "选择地图应用",
  123. cancel: "取消",
  124. buttons: [{title: "腾讯地图"},{title: "百度地图"}, {title: "高德地图"}]
  125. }, function(item) {
  126. let tit = ''
  127. switch (item.index) {
  128. case 1:
  129. tit = '腾讯地图'
  130. url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
  131. break;
  132. case 2:
  133. tit = '百度地图'
  134. url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&content=${name}&src=ios.baidu.openAPIdemo&coord_type=gcj02`;
  135. break;
  136. case 3:
  137. tit = '高德地图'
  138. url = `iosamap://viewMap?sourceApplication=applicationName&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
  139. break;
  140. default:
  141. break;
  142. }
  143. if (url != "") {
  144. url = encodeURI(url);
  145. plus.runtime.openURL(url, function(e) {
  146. uni.showToast({
  147. title: '未安装 ' + tit,
  148. icon: 'none'
  149. })
  150. // plus.nativeUI.alert("本机未安装指定的地图应用");
  151. });
  152. }
  153. })
  154. }
  155. }
  156. }
  157. }
  158. </script>
  159. <style scoped lang="scss">
  160. .container {
  161. position: relative;
  162. }
  163. .address_icon {
  164. height: 48rpx;
  165. width: 48rpx;
  166. margin-right: 10rpx;
  167. }
  168. .text {
  169. color: #ffffff;
  170. font-family: PingFang SC, PingFang SC;
  171. font-weight: 400;
  172. font-size: 30rpx;
  173. }
  174. .location {
  175. height: 98rpx;
  176. width: 98rpx;
  177. }
  178. .footer {
  179. position: fixed;
  180. bottom:0;
  181. left: 0;
  182. width:750rpx;
  183. padding: 40rpx 0 40rpx 0;
  184. z-index: 998;
  185. // box-sizing: border-box;
  186. display: flex;
  187. flex-direction: column;
  188. justify-content:center;
  189. align-items: center;
  190. }
  191. .infobox {
  192. margin-top: -40rpx;
  193. width: 670rpx;
  194. padding: 20rpx;
  195. // box-sizing: border-box;
  196. border-radius: 16rpx;
  197. background-color: #282c34;
  198. position: relative;
  199. display: flex;
  200. flex-direction: row;
  201. justify-content:space-between;
  202. align-items: center;
  203. }
  204. .infobox-title {
  205. margin-bottom: 20rpx;
  206. display: flex;
  207. flex-direction: row;
  208. align-items: center;
  209. }
  210. </style>