Skip to content

Instantly share code, notes, and snippets.

@Antoinebr
Created March 21, 2016 20:46
Show Gist options
  • Select an option

  • Save Antoinebr/5aabd4953c8d57ed8c0a to your computer and use it in GitHub Desktop.

Select an option

Save Antoinebr/5aabd4953c8d57ed8c0a to your computer and use it in GitHub Desktop.
Quick & dirty gmap API use
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='http://fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<iframe src="//giphy.com/embed/DAvtGjFMkUfPG" width="480" height="339" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>
<form method="post">
<input name="adresseDepart" type="text" placeholder="Adresse de Départ" required="required">
<input name="adresseArrive" type="text" placeholder="Addresse d'Arrive" required="required">
<input name="prixKm" type="number" placeholder="prix du KM" required="required">
<button type="submit"> Calculer le prix </button>
</form>
<?php
if( isset($_POST['adresseDepart']) && isset($_POST['adresseArrive']) && isset($_POST['prixKm'])){
$start = htmlspecialchars(str_replace(' ', ',', $_POST['adresseDepart']));
$end = htmlspecialchars(str_replace(' ', ',', $_POST['adresseArrive']));
$prixKm = htmlspecialchars($_POST['prixKm']);
$json = json_decode(file_get_contents('http://maps.googleapis.com/maps/api/distancematrix/json?origins='.$start.'s&destinations='.$end.'&mode=driving&language=en-EN&sensor=false'), true);
$distance = $json["rows"][0]["elements"][0]["distance"]["value"];
echo ' <p>Il y\'a '.($distance/1000).' KM entre les deux points par la route </p>';
echo ' </br>';
echo '<p> A '.$prixKm.' € du KM cela donne ';
echo ($distance/1000)*$prixKm;
echo '€ </p>';
}
?>
</html>
<style>
input{
width: 50%;
height: 50px;
display: block;
margin: auto;
margin-top: 10px;
}
button{
width: 50%;
height: 50px;
display: block;
margin: auto;
margin-top: 10px;
}
p{
text-align: center;
}
iframe{
display: block;
margin: auto;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment