2011-06-28 14 views
1

ジオロケーションを携帯電話からJSFバッキングBeanに送信する例はありますか?ジオロケーションJSF

ジオロケーションを使用して顧客の住所を取得しますか? (ジオロケーションの座標を近くの道路のドロップダウンリストに変換する必要があります)。

おかげで、これはUが始めるのに役立つでしょうかどうかわから D

+0

これも私の質問です!誰かが助けてくれる! –

答えて

0

ない...

は、このフォームにモバイルデバイスからGPS地理位置情報データを引き出し... が続いてそこからそれを何でもJavascriptを使用して...

<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

あなたは座標を取得することができますし、JavaScriptで)のdocument.getElementById(「ID」)を使用してバックエンドの変数を設定することができます。

例:

<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

見るこのリンクしてください:

- 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

リンクが壊れたり変化したりする可能性があるため、リンクを投稿するのではなく、ここに回答を投稿してください。 – Prudhvi