disanfanfNav.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view style="width: 380rpx;background-color: white;border-radius: 20rpx;">
  3. <view class="contentColumnC" style="width: 100%;margin-top: 10rpx;">
  4. <view v-if="hasgoogle" class="contentInRowC wanchengV" @click="openNav(1)">
  5. <view class="wanchengT">{{$t('user.googleNav')}}</view>
  6. </view>
  7. <view v-if="!isAndroid" class="contentInRowC wanchengV" @click="openNav(2)">
  8. <view class="wanchengT">{{$t('user.appleNav')}}</view>
  9. </view>
  10. <view v-if="hasAmap" class="contentInRowC wanchengV" @click="openNav(3)">
  11. <view class="wanchengT">{{$t('user.gaodeNav')}}</view>
  12. </view>
  13. <view v-if="hasBaiduMap" class="contentInRowC wanchengV" style="margin-bottom: 40rpx;" @click="openNav(4)">
  14. <view class="wanchengT">{{$t('user.baiduNav')}}</view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name:"disanfanfNav",
  22. props:{
  23. lat:'',
  24. lon:'',
  25. cityName:''
  26. },
  27. data() {
  28. return {
  29. isAndroid:false,
  30. hasBaiduMap:true,
  31. hasAmap:true,
  32. hasgoogle:true
  33. };
  34. },
  35. mounted() {
  36. let systemInfo = uni.getSystemInfoSync();
  37. this.isAndroid = systemInfo.platform.toLowerCase() === 'android';
  38. if(this.isAndroid){
  39. this.initAndroidMap();
  40. }
  41. },
  42. methods:{
  43. initAndroidMap(){
  44. this.hasBaiduMap = plus.runtime.isApplicationExist({
  45. pname: 'com.baidu.BaiduMap',
  46. action: 'baidumap://'
  47. });
  48. this.hasAmap = plus.runtime.isApplicationExist({
  49. pname: 'com.autonavi.minimap',
  50. action: 'androidamap://'
  51. });
  52. this.hasgoogle = plus.runtime.isApplicationExist({
  53. pname: 'com.google.android.apps.maps',
  54. action: 'comgooglemaps://'
  55. });
  56. },
  57. openNav(index){
  58. if(this.isAndroid){
  59. let urlNavMap;
  60. if(index==1){
  61. urlNavMap = 'google.navigation:q=' + this.lat + ',' + this.lon;
  62. }
  63. if(index==3){
  64. let urlAmap =
  65. 'androidamap://viewMap?sourceApplication=appname&poiname='+this.cityName+'&lat='+this.lat+'&lon='+this.lon+'&dev=1';
  66. urlNavMap = encodeURI(urlAmap)
  67. }
  68. if(index==4){
  69. let urlBaiduMap =
  70. 'baidumap://map/direction?region=起点&destination='+this.lat+','+this.lon+'&coord_type=wgs84&mode=riding&src=andr.paotuiwang.qishou';
  71. urlNavMap = encodeURI(urlBaiduMap)
  72. }
  73. plus.runtime.openURL(urlNavMap);
  74. }
  75. else{
  76. var url='';
  77. if(index==1){
  78. url='comgooglemapsurl://?daddr='+ this.lat + ',' + this.lon;
  79. }
  80. if(index==2){
  81. url = 'http://maps.apple.com/?q=' +this.cityName + '&ll=' + this.lat + ',' + this.lon + '&spn=0.008766,0.019441';
  82. }
  83. if(index==3){
  84. url ='iosamap://path?sourceApplication=fuxishan_uni_client&dlat='+this.lat+'&dlon='+this.lon+'&dname='+this.cityName+'&dev=1&t=0';
  85. }
  86. if(index==4){
  87. url ='baidumap://map/marker?location='+this.lat+','+this.lon+'&title='+this.cityName+'&content='+this.cityName+'&coord_type=wgs84&src=ios.baidu.openAPIdemo';
  88. }
  89. if (url!='') {
  90. url = encodeURI(url)
  91. plus.runtime.openURL(url, function(e) {
  92. plus.nativeUI.alert(that.$t('user.weianzhuangapp'));
  93. });
  94. }
  95. }
  96. this.$emit('ENavOpen');
  97. },
  98. handlePosition(lat,lon,cityName) {
  99. //如果是Andrios的设备
  100. if (plus.os.name == 'Android') {
  101. console.log('Android')
  102. //重点是下面的url要根据官方给出的api进行对应,不同的需求对应不同的api
  103. let urlBaiduMap =
  104. 'baidumap://map/direction?region=起点&destination='+lat+','+lon+'&coord_type=wgs84&mode=riding&src=andr.paotuiwang.qishou';
  105. urlBaiduMap = encodeURI(urlBaiduMap)
  106. let urlAmap =
  107. 'androidamap://viewMap?sourceApplication=appname&poiname='+cityName+'&lat='+lat+'&lon='+lon+'&dev=1';
  108. urlAmap = encodeURI(urlAmap)
  109. var buttons=[];
  110. if(hasBaiduMap){
  111. buttons.push({
  112. title: this.$t('user.baiduNav'),
  113. value:urlBaiduMap
  114. })
  115. }
  116. if(hasAmap){
  117. buttons.push({
  118. title: this.$t('user.gaodeNav'),
  119. value:urlAmap
  120. })
  121. }
  122. // if(hasgoogle){
  123. // buttons.push({title: this.$t('user.googleNav')})
  124. // }
  125. if(buttons.length==0){
  126. if(hasgoogle){
  127. var url = 'google.navigation:q=' + lat + ',' + lon; //如果是国外应用,应该优先使用这个,会启动google地图。这个接口不能统一坐标系,进入百度地图时会有偏差
  128. plus.runtime.openURL(url);
  129. return;
  130. }
  131. }
  132. plus.nativeUI.actionSheet({
  133. title: this.$t('user.xuanzedaoh'),
  134. cancel: this.$t('index.quxiao'),
  135. buttons: buttons
  136. }, function(e) {
  137. plus.runtime.openURL(buttons[e.index-1].value);
  138. });
  139. } else {
  140. // iOS上获取本机是否安装了百度高德地图,需要在manifest里配置,在manifest.json文件app-plus->distribute->apple->urlschemewhitelist节点下添加(如urlschemewhitelist:["iosamap","baidumap"])
  141. var url='';
  142. var that = this;
  143. plus.nativeUI.actionSheet({
  144. title: this.$t('user.xuanzedaoh'),
  145. cancel: this.$t('index.quxiao'),
  146. buttons: [{
  147. title: this.$t('user.baiduNav')
  148. },{
  149. title: this.$t('user.gaodeNav')
  150. },{
  151. title: this.$t('user.googleNav')
  152. },{
  153. title: this.$t('user.appleNav')
  154. }]
  155. }, function(e) {
  156. switch (e.index) {
  157. case 1:
  158. url ='baidumap://map/marker?location='+lat+','+lon+'&title='+cityName+'&content='+cityName+'&coord_type=wgs84&src=ios.baidu.openAPIdemo';
  159. break;
  160. case 2:
  161. url ='iosamap://path?sourceApplication=fuxishan_uni_client&dlat='+lat+'&dlon='+lon+'&dname='+cityName+'&dev=1&t=0';
  162. break;
  163. case 3:
  164. url='comgooglemapsurl://?daddr='+ lat + ',' + lon;
  165. break;
  166. case 4:
  167. url = 'http://maps.apple.com/?q=' +cityName + '&ll=' + lat + ',' + lon + '&spn=0.008766,0.019441';
  168. break;
  169. default:
  170. break;
  171. }
  172. if (url!='') {
  173. url = encodeURI(url)
  174. plus.runtime.openURL(url, function(e) {
  175. plus.nativeUI.alert(that.$t('user.weianzhuangapp'));
  176. });
  177. }
  178. })
  179. }
  180. },
  181. }
  182. }
  183. </script>
  184. <style>
  185. .wanchengV{
  186. width: 300rpx;
  187. height: 68rpx;
  188. border-radius: 10rpx;
  189. margin-top: 40rpx;
  190. background-color: #006AFF;
  191. }
  192. .wanchengT{
  193. width: 100%;
  194. font-weight: bold;
  195. font-size: 26rpx;
  196. color: white;
  197. border-radius: 8rpx;
  198. text-align: center;
  199. }
  200. </style>