V2EX › Vue.js
navigator.geolocation.getCurrentPosition 没有反应,请教一下如何解决?
By GhostBoy at 2021 年 10 月 28 日 · 2432 次点击<script>
export default {
data() {
},
methods: {
getGPS() {
function success(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
console.log("经度");
console.log(latitude);
}
function error() {
console.log("不能获得您的位置。");
}
if(!navigator.geolocation) {
console.log('Geolocation is not supported by your browser');
} else {
console.log ('Locating…');
navigator.geolocation.getCurrentPosition(success, error);
}
}
}
}
</script>
<template>
<button @click="getGPS">当前位置</button>
</template>
<style scoped>
</style>
点击获取当前位置,只输出 Locating
2 条回复 • 2021-10-29 01:01:12 +08:00
|
1
maxin6 2021 年 10 月 29 日
geolocation 好像需要用户授权,如果用户不授权是获取不到位置的
|
|
2
maxin6 2021 年 10 月 29 日
|
› Vue.js