uniapp 打包app 引入高德地图

一。高德地图注册key值

二。项目中添加配置

 

 

 

 

 

 

三。项目中引用

 

 

 

<view class="home-btom-box" >
  <view class="home-zs">
      <image class="img-addicon" src="../../static/images/com_icon_adress.png" mode=""></image>
      <view class="home-address">住所:{{item.address}}</view>
  </view>
  <view class="home-dhg" @click='goGaod(item.name,item.address,item.lat_lag)'>
     <image class="img-dhicon" src="../../static/images/com_icon_dh.png" mode=""></image>
     <view class="home-dhname">导航</view>
  </view>
</view>
goGaod(name,addre){
                let that = this
                if(timer !=null){
                    clearTimeout(timer)
                }
                timer=setTimeout(function(){
                    that.getLng(name,addre)
           },1000)
            },
            //获取 位置的经纬度
            getLng(name,addre){
                let that = this
                uni.request({
                    url: 'https://restapi.amap.com/v3/geocode/geo',
                    method: 'GET',
                    data: {
                        key: '7757a7501dded9289d*******e6', //高德地图key web的
                        address: addre // 地址
                    },
                    success:function(res){
                        let lo = res.data.geocodes[0].location.split(',')[0]
                        let la = res.data.geocodes[0].location.split(',')[1]
                        that.shop_longtude = lo
                        that.shop_latitide = la
                        that.openMap(name,addre,lo,la)
                    }
                })
            },

openMap(name,addre,lo,la){
  uni.openLocation({
    latitude: Number(la),
    longitude: Number(lo),
    name: name,
    address: addre,
    success: function() {
      console.log('success');
    },
    fail:function(err){
      console.log('打开地图失败',err)
    }
  })
},

 

 

 

 

四,直接打开地图选择地址

 

 

<view class="uni-list-cell-db">
      <view class="addcom-name">住所</view>
      <view class="uni-input-wrapper">
             <input class="input-write" v-model="form.address" placeholder="请输入" />
      </view><image @click="goMaps" class="icon-right" src="../../static/images/com_icon_adress.png" mode=""></image>
</view>

 

goMaps(){
     let that = this
     uni.chooseLocation({
          success: function (res) {
                console.log(res,'res')
                console.log('位置名称:' + res.name);
                console.log('详细地址:' + res.address);
                console.log('纬度:' + res.latitude);
                console.log('经度:' + res.longitude);
                that.form.address = res.address
           }
      });
},

 

 

posted @ 2022-06-21 16:18  IT小姐姐  阅读(1555)  评论(5编辑  收藏  举报