Handle non-phrase search box input by running geocode lookup

master
Skylar Ittner 3 years ago
parent b21986f947
commit 625fcf721f

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1 B

After

Width:  |  Height:  |  Size: 901 B

@ -272,6 +272,21 @@
function dolookup(words) {
try {
words = words.trim().toLowerCase().replace(/\s+/g, ' ');
if (!/^[a-z ]+?$/i.test(words)) {
// Not a FixPhrase, run a search
$.getJSON("lookup.php", {
search: words
}, function (resp) {
if (resp.status == "OK") {
lookupAndShowCoords(resp.coords[0], resp.coords[1]);
} else {
alert("Error: " + resp.msg);
}
});
return;
}
var coords = FixPhrase.decode(words);
showLocationPopup(coords[0], coords[1], coords[3], coords[2]);

@ -57,8 +57,21 @@ try {
$lon
]
];
} else if (!empty($_GET["search"])) {
$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 or a latitude/longitude pair.");
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");

Loading…
Cancel
Save