Ejemplo n.º 1
0
 */
function GetDrivingDistance($lat1, $lat2, $long1, $long2, $mapsApi)
{
    $url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" . $lat1 . "," . $long1 . "&destinations=" . $lat2 . "," . $long2 . "&mode=driving&key=" . $mapsApi;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $response = curl_exec($ch);
    curl_close($ch);
    $response_a = json_decode($response, true);
    $dist = $response_a['rows'][0]['elements'][0]['distance']['text'];
    $time = $response_a['rows'][0]['elements'][0]['duration']['text'];
    return array('distance' => $dist, 'time' => $time);
}
if ($_POST) {
    $sonuc = array();
    $coordinates1['lat'] = $_POST["lat1"];
    $coordinates2['lat'] = $_POST["lat2"];
    $coordinates1['long'] = $_POST["long1"];
    $coordinates2['long'] = $_POST["long2"];
    $mapsApi = $_POST["mapsAps"];
    $dist = GetDrivingDistance($coordinates1['lat'], $coordinates2['lat'], $coordinates1['long'], $coordinates2['long'], $mapsApi);
    $sonuc["Km"] = $dist['distance'];
    $sonuc["Times"] = $dist['time'];
    echo json_encode($sonuc);
} else {
    die("Hacking???");
}
Ejemplo n.º 2
0
		</ul>
	</div>
</nav>

<?php 
$addr1 = "1521 1st Ave, Seattle, WA";
$addr2 = "1301 Alaskan Way, Seattle, WA";
$parts1 = parseAddress($addr1);
$parts2 = parseAddress($addr2);
// $coord1 = get_coordinates("Seattle", "1521 1st Ave", "Washington");
$coord1 = get_coordinates($parts1[1], $parts1[0], $parts1[2]);
$coord2 = get_coordinates($parts2[1], $parts2[0], $parts2[2]);
echo $parts1[1] . " - " . $parts1[0] . " - " . $parts1[2] . "<br>";
echo $parts2[1] . " - " . $parts2[0] . " - " . $parts2[2] . "<br>";
if ($coord1 && $coord2) {
    $dist = GetDrivingDistance($coord1['lat'], $coord2['lat'], $coord1['long'], $coord2['long']);
    echo 'Distance: <b>' . $dist['distance'] . '</b><br>Travel time duration: <b>' . $dist['time'] . '</b>';
} else {
    echo 'Bad address.';
}
?>
	<div style:"text-align:center; display:block; margin:auto;">
	<b>Origin: </b>
	<select id="start">
		<option value="<?php 
echo $addr1;
?>
">rexburg1</option>
		<option value="joplin, mo">Joplin, MO</option>
		<option value="oklahoma city, ok">Oklahoma City</option>
		<option value="amarillo, tx">Amarillo</option>