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
| <!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<?php
require('Connect.php');
$sql="SELECT * FROM `villes_france_free` WHERE `ville_departement` ='91' ";
if(!$pdo->query($sql)) echo "Pb d'accès au CARNET";
else {
?>
<form>
<select name="ville_id">
<?php
foreach ($pdo->query($sql) as $row)
if(!empty($row['ville_nom']))
echo "<option value='".$row['ville_longitude_deg']." ".$row['ville_latitude_deg']."'>"
.$row['ville_code_postal']." ".$row['ville_nom']."</option>\n";
?>
</select>
<?
function get_distance_m($lat1, $lng1, $lat2, $lng2) {
$earth_radius = 6378137; // Terre = sphère de 6378km de rayon
$rlo1 = deg2rad($lng1);
$rla1 = deg2rad($lat1);
$rlo2 = deg2rad($lng2);
$rla2 = deg2rad($lat2);
$dlo = ($rlo2 - $rlo1) / 2;
$dla = ($rla2 - $rla1) / 2;
$a = (sin($dla) * sin($dla)) + cos($rla1) * cos($rla2) * (sin($dlo) * sin($dlo));
$d = 2 * atan2(sqrt($a), sqrt(1 - $a));
return ($earth_radius * $d);
}
echo (round(get_distance_m(48.856667, 2.350987, echo "['ville_longitude_deg']", echo "['ville_latitude_deg']") / 1000, 3)). ' km';
?>
</form>
<?php
}
?>
</body>
</html> |
Partager