-
Notifications
You must be signed in to change notification settings - Fork 1
/
caluclate_saving.php
65 lines (45 loc) · 2.03 KB
/
caluclate_saving.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
61
62
63
64
65
<?php
//$source
//$destination
//Calcualte distance, time
//Calcuate fare
//return
//hotel price
header('Content-Type: application/json');
include("geo_calculator.php");
$source = $_GET['usersource'];
$destination = $_GET['destination'];
//var_dump($destination);die;
echo getSaving($source, $destination);
function getSaving($source, $destination){
$data = getDistance($source, $destination);
$fare = calculateFare($data["distance"]);
$duration = minToHours(calculateDuration($data["distance"]));
$start_date = "06/03/2015";
$end_date = "09/03/2015";
$geoCordinates = get_lat_long($destination);
$hotelPrice = getStayzillahotel($geoCordinates[0], $geoCordinates[1], $start_date, $end_date);
$Price = $hotelPrice->hotels[0]->rawPrice;
$stayzillaSource = $hotelPrice->hotels[0]->address;
$data_User = array("distance" => $data["distance"], "duration" => $duration,
"cabFare" => $fare);
$stayzillaData = getDistance($stayzillaSource, $destination);
$stayZillaDistance = number_format((float)$hotelPrice->hotels[0]->distanceFromLatLong / 1000, 2, '.', '');
$stayzillafare = calculateFare($stayZillaDistance);
$stayzillaDuration = minToHours(calculateDuration($stayZillaDistance));
$data_stayzilla = array("distance" => $stayZillaDistance." km", "duration" => $stayzillaDuration,
"cabFare" => $stayzillafare, "hotelFare" => $Price, "hotelData" => $hotelPrice->hotels[0]);
$responceData = array();
$responceData["user"] = $data_User;
$responceData["stayzilla"] = $data_stayzilla;
return json_encode($responceData);
}
function get_lat_long($address){
$address = str_replace(" ", "+", $address);
$json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false®ion=$region");
$json = json_decode($json);
$lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
return array($lat, $long);
}
?>