-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
60 lines (55 loc) · 1.62 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
require_once 'connection.php';
if(isset($_POST['submit']))
{
$nom=$_POST['nom'];
$latitude=$_POST['latitude'];
$longitude=$_POST['longitude'];
$query=mysqli_query($conn,
"INSERT INTO `tb_data` VALUES ('','$nom','$latitude','$longitude')");
echo
"
<script>
alert('Donnée bien ajoutée');
document.location.href='geo.php';
<script>
";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insertion des données</title>
</head>
<body onload="getLocation();">
<form class="myForm" action="" method="post",autocomplete="off">
<label for="">Nom</label>
<input type="text" name="nom" required> <br>
<input type="text" name="latitude" >
<input type="text" name="longitude" > <br>
<button type="submit" name="submit">Envoyer</button>
</form>
<script type="text/javascript">
function getLocation(){
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
}
function showPosition(position) {
document.querySelector('.myForm input[name="latitude"]').value=position.coords.latitude+1.79108-0.040800000000000;
document.querySelector('.myForm input[name="longitude"]').value=position.coords.longitude+0.0757;
}
function showError(error){
switch(error.code){
case error.PERMISSION_DENIED:
alert("You must allow geolocation");
location.reload();
break;
}
}
</script>
</body>
</html>