geolocation GPS좌표값 스크립트에서 php 변수 뽑아오기 > 그누보드5 팁자료실

그누보드5 팁자료실

geolocation GPS좌표값 스크립트에서 php 변수 뽑아오기 정보

geolocation GPS좌표값 스크립트에서 php 변수 뽑아오기

본문

<p id="demo"></p>
<script>
var x = document.getElementById("demo");

function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.watchPosition(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;
window.location.assign("map.php?var1="+position.coords.longitude+"&var2="+ position.coords.latitude);
}
getLocation();
</script>

 

map.php 파일

 

<?php

$lon = $_GET["var1"];
$lat = $_GET["var2"];
$time = date('d/m/Y H:i:s');
$fp = fopen('dati.txt', 'a+');
fwrite($fp, "{$time} | {$_SERVER['REMOTE_ADDR']} | {$_SERVER['HTTP_USER_AGENT']} | {$lon} | {$lat} | \n");
fclose($fp);

?>

dati.txt 아이피 브라우저 gps 좌표 저장이 됩니다.

추천
2
  • 복사

댓글 4개

© SIRSOFT
현재 페이지 제일 처음으로