首页 > 解决方案 > 如何在 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”插件,它也给出了相同的结果,请提出一种更好的方法来获取用户的准确位置坐标。

标签: javascriptvue.jsvuejs2geolocationgoogle-location-services

解决方案


推荐阅读