日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

app 隔几秒记录当前经纬度位置_uni-app获取位置经纬度并定位到当前位置

發(fā)布時間:2024/9/19 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 app 隔几秒记录当前经纬度位置_uni-app获取位置经纬度并定位到当前位置 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

uni-app使用map組件定位到當(dāng)前位置并進行標注

manifest.json添加如下內(nèi)容:

需要定位的頁面

style="width: 100vw; height: 100vh;"

:latitude="latitude"

:longitude="longitude"

:scale="scale"

:markers="markers"

>

export default {

data() {

return {

latitude: 39.909, // 默認定在首都

longitude: 116.39742,

scale: 12, // 默認16

markers: [],

markerHeight: 30,

};

},

methods: {

// 初次位置授權(quán)

getAuthorize() {

return new Promise((resolve, reject) => {

uni.authorize({

scope: "scope.userLocation",

success: () => {

resolve(); // 允許授權(quán)

},

fail: () => {

reject(); // 拒絕授權(quán)

},

});

});

},

// 確認授權(quán)后,獲取用戶位置

getLocationInfo() {

const that = this;

uni.getLocation({

type: "gcj02",

success: function (res) {

// 暫時

that.longitude = res.longitude; //118.787575;

that.latitude = res.latitude; //32.05024;

that.markers = [

{

id: "",

latitude: res.latitude,

longitude: res.longitude,

iconPath: "../../static/mark.png",

width: that.markerHeight, //寬

height: that.markerHeight, //高

},

];

that.getList();

},

});

},

// 拒絕授權(quán)后,彈框提示是否手動打開位置授權(quán)

openConfirm() {

return new Promise((resolve, reject) => {

uni.showModal({

title: "請求授權(quán)當(dāng)前位置",

content: "我們需要獲取地理位置信息,為您推薦附近的美食",

success: (res) => {

if (res.confirm) {

uni.openSetting().then((res) => {

if (res[1].authSetting["scope.userLocation"] === true) {

resolve(); // 打開地圖權(quán)限設(shè)置

} else {

reject();

}

});

} else if (res.cancel) {

reject();

}

},

});

});

},

// 徹底拒絕位置獲取

rejectGetLocation() {

uni.showToast({

title: "你拒絕了授權(quán),無法獲得周邊信息",

icon: "none",

duration: 2000,

});

},

getList() {

console.log("獲取周圍美食");

},

},

onReady() {

// wx請求獲取位置權(quán)限

this.getAuthorize()

.then(() => {

// 同意后獲取

this.getLocationInfo();

})

.catch(() => {

// 不同意給出彈框,再次確認

this.openConfirm()

.then(() => {

this.getLocationInfo();

})

.catch(() => {

this.rejectGetLocation();

});

});

},

};

總結(jié)

以上是生活随笔為你收集整理的app 隔几秒记录当前经纬度位置_uni-app获取位置经纬度并定位到当前位置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。