Commit b32bce2e authored by michael lundquist's avatar michael lundquist
Browse files

Got a working version longLatZip running, so I can get the longitude and...

Got a working version longLatZip running, so I can get the longitude and latitude of the central zip code.
parent 4a7a6d87
<?php
include_once(dirname(__FILE__)."/queryPrep.php");
//echo phpinfo();
$res = resultQuery("select count(*) from zip",[]);
echo $res->num_rows."<br/>";
echo $res->fetch_row()[0]."<br/>";
$res->close();
/*
returns the longitude and latitude of a zip code,
or false if the zipcode doesn't exist
*/
function longLatZip($zip){
$sql = "select * from zip where P = ?";
$param = Array(0 => $zip);
$result = resultQuery($sql, $param);
$retVal = False;
if($result->num_rows > 0){
$retVal = $result->fetch_assoc();
$result->close();
}
return $retVal;
}
/*
calculating
https://stackoverflow.com/questions/24370975/find-distance-between-two-points-using-latitude-and-longitude-in-mysql/24372831#24372831
*/
function nearbyZips($zip, $maxDistance){
$zipArr = longLatZip($zip);
if(!$zipArr) return false;
$sql = "SELECT a.city AS from_city, b.city AS to_city,
69.0 *
DEGREES(ACOS(COS(RADIANS(a.Latitude))
* COS(RADIANS(b.Latitude))
* COS(RADIANS(a.Longitude - b.Longitude))
+ SIN(RADIANS(a.Latitude))
* SIN(RADIANS(b.Latitude)))) AS distance_in_mi
FROM city AS a
JOIN city AS b ON a.id <> b.id
WHERE a.city = 3 AND b.city = 7";
$params = [];
}
print_r(longLatZip(20194));
?>
HELLO WORLD!
\ No newline at end of file
......@@ -4,7 +4,7 @@ if(is_dir(dirname(__FILE__)."/../zipAPI")){
//localhost
define("PHP_ROOT", $_SERVER["DOCUMENT_ROOT"]."/zipAPI");
define("HTML_ROOT", "/zipAPI");
define("URL", "http://localhost/nuts/nutrition/");
define("URL", "http://127.0.0.1/nuts/nutrition/");
}elseif(is_dir(dirname(__FILE__)."/../../public_html")){
//SMS
define("PHP_ROOT", $_SERVER["DOCUMENT_ROOT"]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment