日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

uniapp 微信小程序導航功能(從地址列表內點擊某一個地址)

作者:maoge_666 更新時間: 2023-07-16 編程語言

效果圖:
在這里插入圖片描述

<template>
	<view class="user">
		<view class="list">
			<view class="title">地址列表</view>
			<view class="title-label">
				<view>名稱</view>
				<view>距離(由近到遠排序)</view>
			</view>
			<view class="item" v-for="(item,index) in sortingList" :key="index">
				<view class="item-top">
					<view class="item-top-left">{{item.placeName}}</view>
					<view class="item-top-right">
						<view>{{item.designCapacity}}km</view>
						<view class="view-btn" @click="toNavigation(item.longitude,item.latitude,item.placeName,item.temporaryAddress)">
							<image src="../../static/img/view-btn.png"></image>
						</view>
					</view>
				</view>
				<view class="item-bottom">地址:{{item.temporaryAddress}}</view>
			</view>
			<!-- 到底了~ -->
			<view class="loadall" v-if="sortingList.length > 10 && loadAll">已加載全部數據</view>
			<!-- 空 -->
			<view class="empty" v-if="!sortingList.length">
				<view class="empty-text">暫無數據</view>
			</view>	
		</view>
	</view>
</template>

<script>
	var http = require("../../utils/http.js");
	var config = require("../../utils/config.js");
	export default {
		data() {
			return {
				sortingList: [],//地址列表
				longitude: '', // 經度(當前用戶位置)
				latitude: '',// 緯度(當前用戶位置)
				loadAll: false ,// 已加載全部
				current: 1,
				total:0,//總數量
				pageSize:10,//每頁查詢數量
			}
		},
		components: {},
		props: {},
		computed:{},
		
		/**
		 * 生命周期函數--監聽頁面加載
		 */
		onLoad: function (options) {
			this.getCurrentLocation()
		},
		
		/**
		 * 生命周期函數--監聽頁面初次渲染完成
		 */
		onReady: function () {},
		
		/**
		 * 生命周期函數--監聽頁面顯示
		 */
		onShow: function () {
		  	this.current = 1
			this.sortingList = []
			this.getSortingList(1)
				
		},
		
		/**
		 * 生命周期函數--監聽頁面隱藏
		 */
		onHide: function () {},
		
		/**
		 * 生命周期函數--監聽頁面卸載
		 */
		onUnload: function () {},
		
		/**
		 * 頁面相關事件處理函數--監聽用戶下拉動作
		 */
		onPullDownRefresh: function () {},
		
		/**
		 * 頁面上拉觸底事件的處理函數
		 */
		onReachBottom: function () {
			if (this.current < this.total/this.pageSize) {
				this.current ++;
				this.getSortingList(1)
			} else {
				this.loadAll = true
			}
		},
		methods: {
			//通過自帶的方法獲取到當前的經緯度
			getCurrentLocation() {
				let that = this 
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						console.log("當前位置信息:",res)
						that.longitude = res.longitude; // 經度
						that.latitude = res.latitude;// 緯度
					},
					fail: function(error) {
						uni.showToast({
							title: '無法獲取位置信息!無法使用位置功能',
							icon: 'none',
						})
					}
				});
			},
			// 獲取地址列表
			getSortingList: function(current) {
				uni.showLoading();
				var params = {
					url: "/xxx/xxx",
					method: "GET",
					data: {
						pageNum: this.current,
						pageSize: 10,
						longitude: this.longitude, // 經度
						latitude: this.latitude // 緯度
					},
					callBack: res => {
						uni.hideLoading()
						this.sortingList = this.sortingList.concat(res.rows);
						this.total = res.total;
					}
				};
				http.request(params);
			},
			//導航--傳終點的坐標即可
			toNavigation: function(endLongitude,endLatitude,placeName,temporaryAddress) {
				console.log("返回的坐標:",endLongitude,endLatitude)
				uni.openLocation({
					longitude: parseFloat(endLongitude),
					latitude: parseFloat(endLatitude),
					scale: 28, // 縮放比例TODO
					name:placeName,//地點名稱
				    address:temporaryAddress,//地點詳細地址
					success: function (res) {
						console.log('success:',res);
					}
				});
			},
		}
	}
</script>
<style>
	page {
	background: #f4f4f4;
}
.list{
	margin-top: 32rpx;
}
.title{
	font-size: 34rpx;
	color: #333333;
	text-align: center;
}
.title-label{
	margin-top: 27rpx;
	margin-bottom: 24rpx;
	display: flex;
	justify-content: space-between;
	font-size: 30rpx;
	color: #666666;
	padding-left: 22rpx;
	padding-right: 22rpx;
}
.item{
	width:100%;
	padding: 17rpx 22rpx 28rpx 22rpx;
	background: #FFFFFF;
	margin-bottom: 28rpx;
	box-sizing:border-box;
}
.item-top{
	height: 56rpx;
	line-height: 56rpx;
	margin-bottom: 27rpx;
	font-size: 30rpx;
	color: #333333;
	display: flex;
	justify-content: space-between;
}
.item-top-right{
	display: flex;
	justify-content: space-between;
	height: 56rpx;
	line-height: 56rpx;
}
.item-bottom{
	font-size: 30rpx;
	color: #666;
}
.view-btn{
	width: 200rpx;
	height: 58rpx;
	border-radius: 60rpx;
	margin-left: 10rpx;
}
.view-btn  image{
	width:100%;
	height:100%;
} 
.empty-text {
  font-size: 28rpx;
  text-align: center;
  color: #999;
  line-height: 2em;
}
.loadall{
	font-size: 28rpx;
	text-align: center;
	color: #999;
	line-height: 2em;
	margin-bottom: 20rpx;
}

</style>

原文鏈接:https://blog.csdn.net/maoge_666/article/details/131580694

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新