In this example when the user clicks anywhere inside this form his location will be obtained by the javascript function.
I am by setting the value in a hidden field to I have how to access this value in the backend, that is, in my controller or bean.
Full Example :
<script type="text/javascript">
$(document).ready(function() {
myIP = function(){
navigator.geolocation.getCurrentPosition(function(position) {
var valor = position.coords.latitude + ',' + position.coords.longitude;
$( ".latlong").val(valor);
});
return false;
}
});
</script>
<h:form id="form" onclick="myIP()">
<h:inputText styleClass="latlong" style="display:none" id="latlong" value="#{myController.latlong}"/>