I'm trying to implement the HTML5 Geolocation
when I click on the submit_tag
in the following form. But the prompt for permission does not popup. Any idea why this is happening??
search_controller.rb
<%= form_for search_path, method: :get do |f| %>
<p>
<%= f.label "Search for" %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "search", name: nil , :onclick => "getLocation();" %>
</p>
<% end %>
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<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) {
// Do something with the coordinates
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
</body>
</html>
<h3> Results:</h3>
<% @las.each do |la| %>
<li><%= link_to la.title, item %>
<%= number_to_currency la.price %>
(<%= la.distance.round(1) %> km) </li>
<% end %>