V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
GhostBoy
V2EX  ›  Vue.js

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

  •  
  •   GhostBoy · 2021-10-28 17:50:31 +08:00 · 1281 次点击
    这是一个创建于 903 天前的主题,其中的信息可能已经有所发展或是发生改变。
    <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
    maxin6
        1
    maxin6  
       2021-10-29 00:51:15 +08:00
    geolocation 好像需要用户授权,如果用户不授权是获取不到位置的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5495 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 06:33 · PVG 14:33 · LAX 23:33 · JFK 02:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.