项目场景:
用uniapp 实现签到签退(使用高德的api)
问题描述
提示:这里描述项目中遇到的问题:
例如:使用uniapp 自带的组件不能实现点击地图 再签退
提示思路:
提示:使用uniapp (写入2个script,第一个script,放自己本身的方法,第二个script放加载地图的方法)
解决方案:
<view id="amap" class="amap" :prop="locationInfo" :change:prop="amap.updateEcharts" @click="amap.onClick" ></view>
//获取经纬度
async getAddress(){
let _this=this;
return new Promise((resolve, reject) => {
uni.getLocation({
type: 'wgs84',
geocode:true,
success: function(res) {
_this.lng= [res.longitude,res.latitude]
resolve(_this.lng)
}
});
})
},getPoe(){
getInfo().then(res=>{
this.sginPro.roleName=res.data.roles[0].roleName
this.sginPro.roleId =res.data.roles[0].id
})
},//第二个script
updateEcharts(newValue, oldValue, ownerInstance, instance) {
// console.log(newValue,oldValue,'00000')
this.lng=newValue.lng
this.lat=newValue.lat
// this.initMarkers()
},getAddress(){
let _this=this;
var geoCoder;
this.map.plugin(['AMap.Geocoder'],function(){
geoCoder = new AMap.Geocoder({
city: ""//城市,默认:“全国”
});
var lnglatXY = _this.lat !== ''?[_this.lng,_this.lat]:''; // 地图上所标点的坐标
geoCoder.getAddress(lnglatXY, function(status, result) {
_this.sginPro.signInAddress = result.regeocode.formattedAddress;
_this.onClick(null,_this.ownerInstance,_this.sginPro.signInAddress)
_this.$ownerInstance.callMethod('onViewClick', _this.sginPro.signInAddress)
})
})
},