uniapp小程序地图点击获取指定位置的经纬度
在微信小程序更新之后,bindtap方法可以返回指定位置的经度纬度
直接使用uni的@tap方法即可获取到指定位置的经度纬度
效果
也可以设置多个,拿到经度纬度之后想怎么样就怎么样了
<template>
<view class="">
<map style="width: 100%; height: 50vh;" :markers="markers" :latitude="latitude" :longitude="longitude" @tap="getRes"></map>
</view>
</template>
<script>
export default {
data() {
return {
title: 'map',
latitude: 39.909,
longitude: 116.39742,
markers:[{
width : 40,
height: 40,
latitude: 39.909,
longitude: 116.39742,
iconPath: '/static/定.png',
}]
}
},
methods: {
getRes:function(e){
console.log(e) //这里直接获取到点击的地方的经度纬度
this.markers=[{}]
this.markers[0].width=40
this.markers[0].height=40
this.markers[0].latitude=e.detail.latitude
this.markers[0].longitude=e.detail.longitude
this.markers[0].iconPath='/static/定.png'
}
}
}
</script>
<style>
</style>