首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Vue.js -地理定位不适用于移动设备.为什么?

Vue.js -地理定位不适用于移动设备.为什么?
EN

Stack Overflow用户
提问于 2018-03-04 15:14:56
回答 1查看 1K关注 0票数 1

我试着用Vue组件访问地理定位--在桌面浏览器上,它正在工作,但是在移动浏览器上,它不工作.

用于测试http://www.padermeet.de/geolocation的url

原因是什么?

代码语言:javascript
运行
复制
<template>
    <div>
        <p>Click the button to get your coordinates.</p>
        <button @click="getLocation">Try It</button>
        <p id="demo" v-text="text"></p>
    </div>
</template>

<script>
    export default {
        data(){
            return {
                text: 'Hier wird deine Latitude und Longitude angezeigt.',
                lat: '',
                lng: ''
            }
        },
        methods: {
            getLocation() {
                if (window.navigator.geolocation) {
                    window.navigator.geolocation.getCurrentPosition(this.showPosition);
                } else { 
                    text = "Geolocation is not supported by this browser.";
                }
            },
            showPosition(position) {
                this.lat = position.coords.latitude,
                this.lng = position.coords.longitude,
                this.text = "deine Location befindet sich in: Latitude:" + this.lat + " und Longitude: " + this.lng;
            } 

        }
    }
</script>

<style lang="scss">
</style>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-04 15:22:21

在铬上的地理位置不工作在非安全来源。

getCurrentPosition()和watchPosition()不再适用于不安全的起源。要使用此特性,应考虑将应用程序切换到安全来源,如HTTPS。

您需要一个https来正确地处理它。

参考文献

https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins

希望这能有所帮助

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49096855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档