0

getLocation()ページの読み込み時にこの関数を呼び出しています:

<script>
function getLocation()
{
    if (navigator.geolocation)
    {
        navigator.geolocation.getCurrentPosition(showPosition,showError);
    }
}
function showPosition(position)
{
    var latlon=position.coords.latitude+","+position.coords.longitude;
    //alert("Your location: "+latlon);
    document.getElementById("latitude").value = coords.latitude;
    document.getElementById("longitude").value = coords.longitude;
}
function showError(error)
{

}

その後、HTML で 2 つの隠し値を定義しました。

<FORM id="myForm" action="insertar.php" method="post" enctype="multipart/form-data" data-ajax="false">
    ....Some other controls...
<input type="hidden" id="latitude" name="latitude" value="">
<input type="hidden" id="longitude" name="longitude" value="">
</FORM>

この関数では、2 つの非表示の値latitudelongitudeユーザーの現在の場所を設定しています。しかし、PHP フォーム POST では、これら 2 つの値が渡されません。どうしたの?

4

2 に答える 2

1

この2行はこうあるべきだと思う

document.getElementById("latitude").value = position.coords.latitude;
document.getElementById("longitude").value = position.coords.longitude;
于 2013-08-03T19:08:30.313 に答える