Ruby on rails 4 使用IP地址访问用户的当前位置
是否有任何解决方案可以访问用户当前位置 我使用geocoder gemRuby on rails 4 使用IP地址访问用户的当前位置,ruby-on-rails-4,Ruby On Rails 4,是否有任何解决方案可以访问用户当前位置 我使用geocoder gem @request = request.location 但它会给出保留或无条目首先将此代码放在html页面中 <script> var x = document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosi
@request = request.location
但它会给出保留或无条目首先将此代码放在html页面中
<script>
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) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
您将从该代码中获得该位置的纬度和经度。然后将该纬度和经度值与geocoder gem一起使用。
您将能够找到该位置的地址
你也可以从这里看到。
可能重复的答案我能知道这个答案有什么错误吗?因为有人不喜欢这个