我试着用Vue组件访问地理定位--在桌面浏览器上,它正在工作,但是在移动浏览器上,它不工作.
用于测试http://www.padermeet.de/geolocation的url
原因是什么?
<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>发布于 2018-03-04 15:22:21
在铬上的地理位置不工作在非安全来源。
getCurrentPosition()和watchPosition()不再适用于不安全的起源。要使用此特性,应考虑将应用程序切换到安全来源,如HTTPS。
您需要一个https来正确地处理它。
参考文献
希望这能有所帮助
https://stackoverflow.com/questions/49096855
复制相似问题