uniapp小程序打开地图选择位置demo效果wx.chooseLocation(整理)

效果图:
在这里插入图片描述

<template>
	<view class="address">
		<view class="container">
			<button bindtap='getLocation'>打开地图选择位置</button>
			<view wx:if="{
    
    {address !=''}}">
				<view>位置名称:{
    
    {
    
    name}}</view>
				<view>详细地址:{
    
    {
    
    address}}</view>
				<view>纬度:{
    
    {
    
    latitude}}</view>
				<view>经度:{
    
    {
    
    longitude}}</view>
			</view>
		</view>
	</view>

	</view>
</template>

<script>
	export default {
    
    
		components: {
    
    
			name: '',
			address: '',
			latitude: '',
			longitude: '',
		},
		data() {
    
    
			return {
    
    
				pageNum: 1,
				data: {
    
    
					name: '',
					address: '',
					latitude: '',
					longitude: ''
				},
			}
		},
		// 页面加载
		onLoad(e) {
    
    
			uni.hideTabBar(); //不让底部显示tab选项
			this.getData();
		},
		// 页面显示
		onShow() {
    
    

		},
		// 方法
		methods: {
    
    
			//获取数据
			getData() {
    
    
				var _this = this;
				wx.chooseLocation({
    
    
					success: function(res) {
    
    
						var name = res.name
						var address = res.address
						var latitude = res.latitude
						var longitude = res.longitude
						
						console.log(name,address,latitude,longitude,'58')
					},
					complete(r) {
    
    
						// 点击确定完成以后-进入对应的页面
						console.log(r,'71');
					}
				})

			},
			//获取列表数据
			getListData() {
    
    
				this.$.ajax("POST", "/xxxxx/xxxxx", {
    
    
					page: this.pageNum,
				}, (res) => {
    
    
					if (res) {
    
    
						if (this.pageNum == 1) {
    
    
							this.list = res.data
						} else {
    
    
							this.list = this.list.concat(res.data)
							if (res.data.length === 0) {
    
    
								this.pageNum--
							}
						}
					}
					uni.stopPullDownRefresh()
				});
			}
		},
		// 计算属性
		computed: {
    
    

		},
		// 侦听器
		watch: {
    
    

		},
		// 页面隐藏
		onHide() {
    
    

		},
		// 页面卸载
		onUnload() {
    
    

		},
		// 触发下拉刷新
		onPullDownRefresh() {
    
    
			this.pageNum = 1
			// this.getListData()
		},
		// 页面上拉触底事件的处理函数
		onReachBottom() {
    
    
			this.pageNum++
			// this.getListData()
		},
	}
</script>

<style lang="scss" scoped>
	.address {
    
    }
</style>

猜你喜欢

转载自blog.csdn.net/qq_38881495/article/details/125392301