module Geoloc::Helper
Public Instance Methods
get_geoloc_form()
click to toggle source
# File lib/geoloc/helper.rb, line 60 def get_geoloc_form html = <<-HTML <script> var lat = document.getElementById("geoloc_latitude"); var lng = document.getElementById("geoloc_longitude"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { x.innerHTML = "Geolocation is not supported by this browser."; } } function showPosition(position) { lat.value = position.coords.latitude; lng.value = position.coords.longitude; } window.onload = getLocation; </script> HTML raw html end
get_geoloc_onload(route, id=nil)
click to toggle source
# File lib/geoloc/helper.rb, line 32 def get_geoloc_onload(route, id=nil) html = <<-HTML <script> var x = document.getElementById("#{id}"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { x.innerHTML = "Geolocation is not supported by this browser."; } } function showPosition(position) { $.post( "#{route}", { data: position }) .done(function( data ) { x.innerHTML = data.data; }); } window.onload = getLocation; </script> HTML raw html end