xytSk-App/pages/xxsb/map.vue

113 lines
2.6 KiB
Vue
Raw Normal View History

2024-06-13 13:50:03 +08:00
<template>
2024-06-19 10:24:04 +08:00
<view>
2024-06-19 15:59:02 +08:00
<view class="page-section page-section-gap">
<map
style="width: 100%; height: 450px"
id="container"
:latitude="lnglat[1]"
:longitude="lnglat[0]"
enable-scroll
enable-rotate
></map>
</view>
2024-06-19 10:24:04 +08:00
<view class="text">
<text class="tit">当前位置</text>
<view id="adds">{{ address }}</view>
</view>
<view class="text">
<p class="tit">/纬度</p>
<view
><span id="lng">{{ lnglat[0] }} {{ lnglat[1] }}</span></view
>
</view>
<u-button
type="primary"
text="确定"
customStyle="margin-top: 50px"
@click="backclick"
></u-button>
2024-06-13 13:50:03 +08:00
</view>
</template>
<script>
2024-06-19 10:24:04 +08:00
// import AMapLoader from '@amap/amap-jsapi-loader'
2024-06-13 13:50:03 +08:00
export default {
2024-06-19 10:24:04 +08:00
name: 'map-view',
2024-06-13 13:50:03 +08:00
data () {
return {
2024-06-19 10:24:04 +08:00
lnglat: [109.139726, 29.665203],
geocoder: null,
marker: null,
geocoder: null,
address: null,
markers: [
{
latitude: 29.665203,
longitude: 109.139726,
iconPath: '../../static/tabs/add.png'
}
]
}
},
2024-06-19 15:59:02 +08:00
mounted () {
2024-06-19 10:24:04 +08:00
this.initAMap()
},
2024-06-19 15:59:02 +08:00
onShow () {},
onLoad () {},
2024-06-19 10:24:04 +08:00
methods: {
backclick () {
this.$emit('back', this.lnglat, this.address)
},
mapClick (val) {
console.log('val', val)
},
initAMap () {
const self = this
console.log('erreee')
uni.getLocation({
type: 'gcj02',
isHighAccuracy: 'true',
geocode: 'true',
success: function (res) {
console.log('res', res)
const latitude = res.latitude
const longitude = res.longitude
// this.lnglat = [109.139726, 29.665203]
self.lnglat = [longitude, latitude]
// this.lnglat = [res.longitude, res.latitude]
console.log('lnglatlnglat', self.lnglat, res)
console.log('地址', res.address)
if (res.address) {
2024-06-19 14:15:15 +08:00
console.log('地址', res.address)
2024-06-19 15:59:02 +08:00
let city = res.address.city ? res.address.city : ''
let district = res.address.district ? res.address.district : ''
let street = res.address.street ? res.address.street : ''
self.address = `${city}${district}${street}`
2024-06-19 10:24:04 +08:00
console.log('地址', self.address)
}
}
})
2024-06-13 13:50:03 +08:00
}
}
}
</script>
2024-06-19 10:24:04 +08:00
<style scoped>
2024-06-19 15:59:02 +08:00
.cont {
2024-06-13 13:50:03 +08:00
width: 100%;
2024-06-19 10:24:04 +08:00
height: 450px;
}
.text {
margin: 10px;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
2024-06-13 13:50:03 +08:00
}
2024-06-19 10:24:04 +08:00
.text .tit {
font-size: 14px;
font-weight: bold;
2024-06-13 13:50:03 +08:00
}
</style>