자바 스크립트를 사용하여 경도와 위도를 가져오고 이전 위치와 비교하기를 원합니다. 다른 컴퓨터에서 로그인 할 때 페이스 북과 같은 것이 있지만 훨씬 더 단순 해집니다. 이를 달성하기 위해 2 개의 숨겨진 필드를 만들었고 사용자가 양식을 제출하면 값이 서버로 전송됩니다.자바 스크립트에서 위치를 가져 와서 PHP로 전달
<body>
<p id="log">Login to continue:
<form action="welcome.php" method="post">
Username: <input type="text" name="user" required >
Password: <input type="password" required>
<input type="hidden" name= "longitude" id="longitude">
<input type= "hidden" name ="latitude" id="latitude">
<input type="submit" name="submit" onclick="getLocation()">
</p>
<script>
var x=document.getElementById("log");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
document.getElementByID("longitude").value = longitude;
document.getElementByID("latitude").value = latitude;
}
</script>
그러나 welcome.php의 코드 :
$latitude=$_POST["latitude"];
$longtude=$_POST["longitude"];
반환 : 공지 사항 : 정의되지 않은 인덱스 : 라인 8 \ XAMPP \ htdocs를 \ welcome.php : C에서 위도
알림 : 정의되지 않은 색인 : 경도 n C : \ xampp \ htdocs \ welcome.php on line 9
더 좋은 방법이 있으며이를 해결하는 방법이 있습니까?
당신은에서 getElementById를 사용하지만 필드 내 의견과 답변 ... – mplungjan