After searching everywhere I couldn't find a concrete answer, I tried to do it as someone did here in the forum and nothing.
I'm not an expert nor do I know much, that's why it's also complicated for me. I need that when sending a form, the coordinates are sent from where the form was sent to my database. (Latitude and longitude) Obviously asking for permission.
I leave a little as is the code so they give me a hand..
<!DOCTYPE html>
<html>
<head>
<title>Vivorata Zona 3</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="estilo.css">
</head>
<body>
<form method="post">
<h1>Vivorata Zona 3</h1>
<input type="text" name="name" placeholder="Nombre Completo">
<input type="text" name="message" placeholder="Mensaje">
<input type="submit" name="register">
</form>
<?php
include("vivorataz3reg.php");
?>
</body>
</html>
--
<?php
include("con_db3.php");
if (isset($_POST['register'])) {
if (strlen($_POST['name']) >=1 && strlen($_POST['message']) >=0) {
$name = trim($_POST['name']);
$message = trim($_POST['message']);
$fecha = date('Y-m-d H:i:s');
$consulta = "INSERT INTO VivorataZ3(nombre, mensaje, fecha) VALUES ('$name', '$message', '$fecha')";
$resultado = mysqli_query($conex, $consulta);
if ($resultado) {
?>
<h3 class="ok">¡Enviado!</h3>
<?php
} else {
?>
<h3 class="bad">¡Ups ha ocurrido un error!</h3>
<?php
}
} else {
?>
<h3 class="bad">¡Completa los campos!</h3>
<?php
}
}
?>
And I found this one that is not bad at all.. But I will surely screw up if I put it without fully understanding it or adding the missing things to make it work well.
<script type="text/javascript">
if (navigator.geolocation) {
alert("¡Permitenos saber tu ubicación!");
navigator.geolocation.getCurrentPosition(mostrarUbicacion);
} else {alert("¡Error! Este navegador no soporta la Geolocalización.");}
function mostrarUbicacion(position) {
var latitud = position.coords.latitude;
var longitud = position.coords.longitude;
var div = document.getElementById("ubicacion");
div.innerHTML = "Ubicación actual:" + latitud + " " + longitud;}
function refrescarUbicacion() {
navigator.geolocation.watchPosition(mostrarUbicacion);}
</script>
What I need is that when entering the page, the browser asks for permission to know the location, fill out the form and when I send it, that it arrive together with the data of the form, its location.