You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB
PHP

<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
$output = [];
try {
if (!empty($VARS["words"])) {
// convert words to coordinates
$words = urldecode($VARS["words"]);
$coords = FixPhrase::decode($words);
$output = [
"status" => "OK",
"action" => "decodeFromWords",
"words" => $words,
"coords" => $coords
];
} else if (!empty($VARS["latitude"]) && !empty($VARS["longitude"])) {
// convert coordinates to words
$lat = round($VARS["latitude"], 4);
$lon = round($VARS["longitude"], 4);
$words = FixPhrase::encode($lat, $lon);
$output = [
"status" => "OK",
"action" => "encodeToWords",
"words" => $words,
"coords" => [
$lat,
$lon
]
];
} else {
throw new Exception("Must supply either a string of words or a latitude/longitude pair.");
}
} catch (Exception $ex) {
sendJsonResp($ex->getMessage(), "ERROR");
}
exitWithJson($output);