navigator.geolocation.getCurrentPosition 没有反应,请教一下如何解决?

2021-10-28 17:50:31 +08:00
 GhostBoy
<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

1294 次点击
所在节点    Vue.js
2 条回复
maxin6
2021-10-29 00:51:15 +08:00
geolocation 好像需要用户授权,如果用户不授权是获取不到位置的
maxin6
2021-10-29 01:01:12 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/811321

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX