聲明
bug: 頁腳的詳細位址在真機測試是會出現不顯示問題?
造成原因:在小程式map元件的同一區域,map元件的視圖層比普通的文本視圖層要高,是以在真機會遮擋!
解決辦法:将該文本視圖采用cover-view,放在map中。
感謝: 感謝Lrj_estranged指出問題!
效果圖

實作原理
- map元件實作定位标記或者指定定位标記,并儲存location。
- 采用高德地圖微信小程式開發API(getRegeo)擷取目前位置或者指定位置的較長的描述。
WXML
<view class="map_container">
<map class="map" longitude="{{longitude}}" latitude="{{latitude}}" include-points="{{points}}" markers='{{markers}}'></map>
<view class="map-tab-bar map-foot {{isShow ? '' : 'map-hide'}}">
<view class="map-name">{{name}}</view>
<view class="map-address">{{address}}</view>
</view>
</view>
複制
JS
擷取目前位置的經緯度解析詳情
const app = getApp();
const amap = app.data.amap;
const key = app.data.key;
Page({
data:{
isShow: true,
longitude:null,
latitude:null,
markers:[],
points:[],
name:'',
address:'',
location:''
},
onLoad(){
var _this = this;
var myAmap = new amap.AMapWX({ key: key });
// 擷取定位位址的描述資料
_this.getRegeo(myAmap);
},
getRegeo(myAmap){
var _this = this;
myAmap.getRegeo({
iconPath: '../../src/images/ding.png',
width: 32,
height: 32,
location: _this.data.location,
success(res) {
var obj = res[0];
if (obj) {
_this.setData({
longitude: obj.longitude,
latitude: obj.latitude,
name: obj.name,
address: obj.desc,
points: [{
longitude: obj.longitude,
latitude: obj.latitude
}],
markers: [{
id: obj.id,
latitude: obj.latitude,
longitude: obj.longitude,
iconPath: obj.iconPath,
width: obj.width,
height: obj.height
}]
})
}
},
fail(res) {
wx.showToast({ title: '失敗!' })
}
})
}
})
複制
擷取指定位置的經緯度解析詳情
// 擷取輸入位址的location
// 假如輸入的是:成都 歐尚庭院
myAmap.getInputtips({
keywords: '歐尚庭院',
city:'成都',
success(res){
_this.setData({
location: res.tips[0].location
})
/************************************************/
// 擷取輸入位址描述資料
_this.getRegeo(myAmap);
/************************************************/
}
})
複制
總結
- 擷取目前定位坐标的經緯度解析詳情,直接調用高德地圖API(getRegeo ),傳回預設目前坐标的詳情。
- 擷取指定定位坐标的經緯度解析詳情,通過高德地圖API(getInputtips)或者微信小程式的API(wx.chooseLocation)擷取指定位置的 location ,通過高德地圖API(getRegeo )擷取坐标解析詳情。