Answer the question
In order to leave comments, you need to log in
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);
if(isset($_POST["coordLat"]) && $_POST["coordLon"] && $_POST["datetime"]) {
$coordLat = $_POST["coordLat"]; // координаты широты
$coordLon = $_POST["coordLon"]; // координаты долготы
$date = $_POST["datetime"]; // дата и время
...............
...............
...............
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question