2011-06-28 5 views
1

Quelqu'un a-t-il un exemple d'envoi d'une géolocalisation d'un téléphone mobile vers un bean backing JSF?Géolocalisation JSF

Vous souhaitez obtenir l'adresse de nos clients en utilisant la géolocalisation? (Il faudra convertir les coordonnées de géolocalisation en une liste déroulante des routes à proximité).

Merci, D

+0

C'est aussi ma question! quelqu'un plz aide! –

Répondre

0

Je ne sais pas si cela vous aidera u commencer ...

Ce GPS tractions Géolocalisation données des appareils mobiles dans un formulaire ... ensuite faire tout avec elle à partir de là ...

<script type="text/javascript"> 
function getLocationConstant() 
{ 
    if(navigator.geolocation) 
    { 
     navigator.geolocation.getCurrentPosition(onGeoSuccess,onGeoError); 
    } else { 
     alert("Your browser or device doesn't support Geolocation"); 
    } 
} 

// If we have a successful location update 
function onGeoSuccess(event) 
{ 
    document.getElementById("Latitude").value = event.coords.latitude; 
    document.getElementById("Longitude").value = event.coords.longitude; 

} 

// If something has gone wrong with the geolocation request 
function onGeoError(event) 
{ 
    alert("Error code " + event.code + ". " + event.message); 
} 
</script> 


<cfform action="gps2.cfm" method="post"> 
Latitude: <input type="text" id="Latitude" name="Latitude" value=""> 
<br><br> 
Longitude: <input type="text" id="Longitude" name="Longitude" value=""> 
<br><br> 
<input type="button" value="Get Location" onclick="getLocationConstant()"/> 
<br><br> 
<input type="submit" value="Add GPS Location" class=small> 
</cfform> 
0

Utilisation du Javascript, vous pouvez obtenir les coordonnées et vous pouvez définir la variable d'arrière-plan en utilisant document.getElementById ("id")) en javascript.

Exemple:

<h:inputText value="{myBean.latitude}" id="latitudeID" /> 



<!DOCTYPE html> 
<html> 
<body> 
<p>Click the button to get your coordinates.</p> 

<button onclick="getLocation()">Try It</button> 

<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) { 
    x.innerHTML = "Latitude: " + position.coords.latitude + 
    "<br>Longitude: " + position.coords.longitude; 

    document.getElementById("formName:latitudeID").value=position.coords.latitude; /* this will set the value in variable */ 
} 
</script> 
</body> 
</html> 
0

Voir ce lien: il vous plaît

- Développeurs Google

https://goo.gl/TD7aiq - jsFiddle

JS:

// Note: This example requires that you consent to location sharing when 
// prompted by your browser. If you see the error "The Geolocation service 
// failed.", it means you probably did not give permission for the browser to 
// locate you. 
function initMap() { 
var map = new google.maps.Map(document.getElementById('map'), { 
center: {lat: -34.397, lng: 150.644}, 
zoom: 6 
}); 
var infoWindow = new google.maps.InfoWindow({map: map}); 
// Try HTML5 geolocation. 
if (navigator.geolocation) { 
navigator.geolocation.getCurrentPosition(function(position) { 
    var pos = { 
    lat: position.coords.latitude, 
    lng: position.coords.longitude 
    }; 
    infoWindow.setPosition(pos); 
    infoWindow.setContent('Location found.'); 
    map.setCenter(pos); 
    }, function() { 
    handleLocationError(true, infoWindow, map.getCenter()); 
    }); 
    } else { 
    // Browser doesn't support Geolocation 
    handleLocationError(false, infoWindow, map.getCenter()); 
    } 
} 
    function handleLocationError(browserHasGeolocation, infoWindow, pos) { 
    infoWindow.setPosition(pos); 
    infoWindow.setContent(browserHasGeolocation ? 
        'Error: The Geolocation service failed.' : 
        'Error: Your browser doesn\'t support geolocation.'); 
    } 
+0

S'il vous plaît poster la réponse ici plutôt que d'afficher le lien que les liens pourraient avoir tendance à casser ou à changer. – Prudhvi