V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
GhostBoy
V2EX  ›  Vue.js

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

  •  
  •   GhostBoy · Oct 28, 2021 · 2084 views
    This topic created in 1641 days ago, the information mentioned may be changed or developed.
    <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 replies    2021-10-29 01:01:12 +08:00
    maxin6
        1
    maxin6  
       Oct 29, 2021
    geolocation 好像需要用户授权,如果用户不授权是获取不到位置的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5627 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 08:35 · PVG 16:35 · LAX 01:35 · JFK 04:35
    ♥ Do have faith in what you're doing.