Add API to convert between coordinates and a 4-word phrase, add PlusCodes to reverse geocoder
parent
3a670076ce
commit
e03c02d416
@ -0,0 +1,46 @@
|
||||
<?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);
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in New Issue