コード例 #1
0
ファイル: info.php プロジェクト: Swati4star/Travel-Mate
<?php

/**
 * @Author: prabhakar
 * @Date:   2016-03-15 16:11:32
 * @Last Modified by:   Prabhakar Gupta
 * @Last Modified time: 2016-03-15 16:21:57
 */
require_once '../inc/connection.inc.php';
require_once '../inc/function.inc.php';
require_once '../inc/constants.inc.php';
$city_id = (int) $_GET['id'];
$response = array();
if ($city_id > 0) {
    $query = "SELECT `city_name`,`description`,`lat`,`lng`,`image` FROM `cities` WHERE `id`='{$city_id}' LIMIT 1";
    $query_row = mysqli_fetch_assoc(mysqli_query($connection, $query));
    if (isset($query_row)) {
        $city_name = ucfirst($query_row['city_name']);
        $response = array('id' => (int) $city_id, 'name' => $city_name, 'description' => trim($query_row['description']), 'lat' => (double) $query_row['lat'], 'lng' => (double) $query_row['lng'], 'image_url' => trim($query_row['image']));
        $response['weather'] = getCityWeather($city_name);
    }
}
echo json_encode($response);
コード例 #2
0
//degToCompass is called and provided a number of degrees. This is then translated into a letter to show direction
function degToCompass($dirDegrees)
{
    $direction = '';
    $directions = array('N' => array(337.5, 22.5), 'NE' => array(22.5, 67.5), 'E' => array(67.5, 112.5), 'SE' => array(112.5, 157.5), 'S' => array(157.5, 202.5), 'SW' => array(202.5, 247.5), 'W' => array(247.5, 292.5), 'NW' => array(292.5, 337.5));
    foreach ($directions as $dir => $angles) {
        if ($dirDegrees >= $angles[0] && $dirDegrees < $angles[1]) {
            $direction = $dir;
            break;
        }
    }
    return $direction;
}
$zipCodes = '';
$weather = '';
$total = 0;
if (isset($_POST['city'])) {
    $total = count($_POST['city']);
    for ($x = 0; $x < $total; $x++) {
        if ($x != 0) {
            $zipCodes .= ', ';
        }
        $zipCodes .= clean_input($_POST['city'][$x]);
    }
    $weather = getCityWeather($_POST['city'], $zipCodes);
}
$data = array("total" => $total, "weather" => $weather, "navbar" => $navbarLinks, "latLong" => $allLatLong);
echo json_encode($data);
?>