私には 3 つのことがあります: 1. 2 つの数値フィールド (標準クラスから)。2. geolocator を使用して座標を抽出する 1 つの Javascript 関数。3. ラジオ ボタン。クリックすると、数値フィールドが動的に入力されます。
以下は、タスクを実行するために使用しているコードですが、機能していません。私を助けてくれませんか?私は何を間違っていますか?よろしくお願いします。
** ジオロケーター機能が正しく動作していることを確認しました。私の問題は、コードを抽出して数値フィールドを動的に入力するコードにあると思います。
add_filter('gform_field_value_longitude', 'populate_longitude');
function populate_longitude($value){
?>
<script type="text/javascript">
$(document).ready(function() {
var x=document.getElementById("latitude");
var y=document.getElementById("longitude");
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showLocation, errorHandler, {enableHighAccuracy:false, maximumAge:60000, timeout:27000});
}else{
alert('Votre navigateur ne prend malheureusement pas en charge la géolocalisation.');
}
});
function showLocation(position){
x.value=position.coords.latitude;
y.value=position.coords.longitude;
}
<input type="radio" value="extract_coordinate" onclick="populate_longitude;">
</script>
<?php
return "$y";
}