W
W
Web Building2021-04-23 16:49:33
PHP
Web Building, 2021-04-23 16:49:33

How to write the user's geo-location to a text file on button click?

Good day, everyone! The question is already in the title itself, and if the user, for example, gave the go-ahead, then how to write it in PHP ?? I want that in one row, in a text file, there was a date and coordinates of latitude and longitude (through spaces, of course). Can anyone suggest how to implement this?
I will not give my entire Jquery, so as not to clog. The code is working - already checked.
I will show only an example of sending Ajax to a PHP handler:

$.ajax({
                    type: 'POST',
                    url: '/coords.php',  // файл, куда сохраняю координаты
                    dataType: 'text',
              cache: false, 
                    data:({'coordLat': 'lat',   // координаты широты
                           'coordLon':  'lon',  // координаты долготы
                           'datetime': 'now'    // дата и время
                    }),
                    success: function(data){
                      // код ...
                    }
                });
    };
    var geoError = function(position) {
      console.log('Error occurred. Error code: ' + error.code);
    };
    navigator.geolocation.getCurrentPosition(geoSuccess, geoError, geoOptions);


And here is my unfinished coords.php What else can I write? How next to save it in coords.txt??

if(isset($_POST["coordLat"]) && $_POST["coordLon"] && $_POST["datetime"]) {
    $coordLat = $_POST["coordLat"];   // координаты широты
    $coordLon = $_POST["coordLon"];   // координаты долготы
            $date = $_POST["datetime"];   // дата и время
     ...............
     ...............
     ...............
}


Thank you for attention!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question