map.js // 拒绝授权后,弹框提示是否手动打开位置授权 export function openConfirm() { return new Promise((resolve, reject) => { uni.showModal({ title: "请求授权当前位置", content: "我们需要获取地理位置信息,为您提供导航", success: (res) => { if (res.confirm) { uni.openSetting().then((res) => { if (res[1].authSetting["scope.userLocation"] === true) { resolve(); // 打开地图权限设置 } else { reject(); } }); } else if (res.cancel) { reject(); } }, }); }); } // 彻底拒绝位置获取 export function rejectGetLocation() { uni.showToast({ title: "你拒绝了授权,无法获得周边信息", icon: "none", duration: 2000, }); } //进行经纬度转换为距离的计算 export function Rad(d) { return d * Math.PI / 180.0; //经纬度转换成三角函数中度分表形式。 } /* 计算距离,参数分别为第一点的纬度,经度;第二点的纬度,经度 默认单位km */ export function getMapDistance(lat1, lng1, lat2, lng2) { var radLat1 = Rad(lat1); var radLat2 = Rad(lat2); var a = radLat1 - radLat2; var b = Rad(lng1) - Rad(lng2); var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); s = s * 6378.137; // EARTH_RADIUS; s = Math.round(s * 10000) / 10000; //输出为公里 //s=s.toFixed(2); return s; } //计算距离 // 初次位置授权 export function getAuthorize() { return new Promise((resolve, reject) => { uni.authorize({ scope: "scope.userLocation", success: () => { resolve(); // 允许授权 }, fail: () => { reject(); // 拒绝授权 }, }); }); } //打开地图 export function openMap(lon, lat) { console.log("获取经纬度ssssfff", lon, lat); //打开地图,并将门店位置传入 uni.getLocation({ success: res => { // res.latitude=lat; // res.longitude=lon; console.log('location success', parseFloat(lat), parseFloat(lon)) uni.openLocation({ latitude: parseFloat(lat), longitude: parseFloat(lon), scale: 18 }) } }) }
主要看onshow和getLocationInfo
<!-- 服务计划 --> <template> <view> <order-box v-for="(order, index) in orders" :key="index" :serviceName="order.name" :distance="order.distance" :name="order.contactPerson" :phone="order.contact" :startTime="order.createTime" :gdnumber="order.workOrderId" :fwtype="order.serviceType" :address="order.address" :buttons="order.buttons" :orderIndex="index" @invokeMethod="invokeMethod" @navigateToDetail="navigateToDetail" /> <view> <!-- 普通弹窗 --> <uni-popup ref="popup" background-color="#fff"> <view class="popup-content padding" :class="{ 'popup-height': type === 'left' || type === 'right' }"> <view class="text" style="text-align: center;width: 50vw;font-size:16px;font-weight: bold;">开始服务 </view> <!-- 表单部分 --> <view class="content margin-top"> <!-- 图片上传 --> <view class="form-item"> <view class="label" style="width:30%;">图片</view> <view class="image-upload"> <img v-if="image" :src="image" alt="Uploaded Image" /> <view v-else class="image-placeholder" @click="uploadImage"> 标签:console,log,color,微信,longitude,订单,res,latitude,导航 From: https://www.cnblogs.com/le-cheng/p/18474416