"OK", "action" => "decodeFromWords", "words" => $words, "coords" => $coords ]; } else if (!empty($_GET["latitude"]) && !empty($_GET["longitude"])) { // convert coordinates to words $lat = round($_GET["latitude"], 4); $lon = round($_GET["longitude"], 4); $words = FixPhrase::encode($lat, $lon); $output = [ "status" => "OK", "action" => "encodeToWords", "words" => $words, "coords" => [ $lat, $lon ] ]; } else if (!empty($_GET["search"])) { /* * Please don't access this API endpoint if forking the code. Substitute for a different API. */ $resp = file_get_contents("https://data.netsyms.net/v1/gis/geocode/?address=" . urlencode($_GET["search"])); $data = json_decode($resp, true); if ($data["status"] == "OK") { $output = [ "status" => "OK", "action" => "geocode", "coords" => $data["coords"] ]; } else { throw new Exception($data["message"]); } } else { throw new Exception("Must supply either a string of words, a latitude/longitude pair, or a search query."); } } catch (Exception $ex) { sendJsonResp($ex->getMessage(), "ERROR"); } exitWithJson($output);