javascript - 如何在 vue js 应用程序中从浏览器获取准确的地理位置
问题描述
我正在构建一个地理定位应用程序,我得到的坐标根本不准确,它至少有 200000 米的差异。
<template>
<button @click="getLocation2">Location</button>
</template>
data(){
return{
options : {
enableHighAccuracy: true,
timeout: 10000
}
}
}
methods :{
success(pos){
var crd = pos.coords;
console.log('Your current position is:');
console.log(`Latitude : ${crd.latitude}`);
console.log(`Longitude: ${crd.longitude}`);
console.log(`More or less ${crd.accuracy} meters.`);
},
error(err){alert(err)},
getLocation2(){
const geo = navigator.geolocation;
geo.getCurrentPosition(this.success, this.error,this.options);
},
}
我还尝试了“vue-browser-geolocation”插件,它也给出了相同的结果,请提出一种更好的方法来获取用户的准确位置坐标。
解决方案
推荐阅读
- python - uWSGI + Django:ImportError:没有名为“wsgi”的模块
- winapi - 在启用 GDI 缩放的 Windows 10 上保存位图
- php - 使用 PHP 修改 WordPress 中的类别模板
- angular - Angular 6 lib 提供程序错误
- bootstrap-4 - 如何限制 Bootstrap datetimepicker 未来的日期?
- machine-learning - 使用 Fortran 导入 MNIST 数据集
- typo3 - TYPO3 - 翻译不显示,总是默认语言
- javascript - jquery加载函数不调用spring boot控制器来替换thymeleaf模板片段
- angular - 如何像我们在angular js中但在angular 5中一样包含html文件?
- javascript - 如何检查所有输入是否已正确填写,然后将其更改为绿色