所以我尝试了地理编码,但它只能根据 IP 地址找到用户位置,但我需要用户的确切纬度和经度值。顺便说一句,IP地址方法的准确性是多少。
最佳答案
向客户端用户询问地理位置权限。您将直接获得坐标,而无需进行任何地理编码。如果用户没有授予您权限,您无论如何都不应该尝试找到他们。
简单的 JS 示例:
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
// Do something with the coordinates
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
更多信息here .
关于ruby-on-rails - 如何找到Rails的确切位置(不是通过IP地址)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44221267/