Google 不恢复当前位置的当前经纬度
Google not revert currect lattitude and longitude of current position
我想在 laravel 中构建定位功能。我正在使用此代码,但它发送的纬度和经度略有不同。
function getLocation()
{
var x = document.getElementById("lat_long");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position)
{
var x = document.getElementById("lat_long");
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
有没有替代品。这样我就可以改进我的结果。
为了获得更高的准确性,您需要将 Options 对象的 enableHighAccuracy 设置为 true。有关该功能的更多详细信息,您可以查看此 link
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function 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.`);
}
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
}
navigator.geolocation.getCurrentPosition(success, error, options);
我想在 laravel 中构建定位功能。我正在使用此代码,但它发送的纬度和经度略有不同。
function getLocation()
{
var x = document.getElementById("lat_long");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position)
{
var x = document.getElementById("lat_long");
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
有没有替代品。这样我就可以改进我的结果。
为了获得更高的准确性,您需要将 Options 对象的 enableHighAccuracy 设置为 true。有关该功能的更多详细信息,您可以查看此 link https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function 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.`);
}
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
}
navigator.geolocation.getCurrentPosition(success, error, options);