From 625fcf721f4751915b6f69773dc7dbf4143114a3 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 13 Nov 2021 17:49:10 -0700 Subject: [PATCH] Handle non-phrase search box input by running geocode lookup --- favicon.ico | Bin 1 -> 901 bytes index.html | 15 +++++++++++++++ lookup.php | 15 ++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/favicon.ico b/favicon.ico index 8b137891791fe96927ad78e64b0aad7bded08bdc..c78c24143f78b321cdf4c3beb12b55f0391ccec8 100644 GIT binary patch literal 901 zcmV;01A6?4P)Px#8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?F zJQ@H1010qNS#tmY4#WTe4#WYKD-Ig~00DqdOjJb!sr2+iHUp{jn%(;YsPhA<^Z)<< z1F7@_s`CS>^v&-5?)m_f`R+wKo89{bsq&rP`#QY#VS%dHPE3Y!jA(wPH$oPkGjBCvKr(|;{n%G6a z_l0te2B`A+{r{w8bttv=45jTDu=UJTR)ceo6R!0OrtS)+?yKVa;Y&s7NIn^$UkpMUBAa_Wre9 zXjF%^ZG53*fT+Ca{Cjqm4yEgh*!tl0{&dgzIJ@@hM?Nu@&&lllncVxjTx6MQesa(G zyXgGX@cq;9{YJp|b$Oa1v-MKM_aL+NpWgcrr0QRStX_hwBb?i#Wp=ja{O3qO=J)=# zZKYoT000VfQchFq|NsA3R{!f)>8?WELjV8)Q%OWYR5;6h(`9#rFc1Y$GTTyJVZB|c zySux)ySuylUoRxX0$JdFftEKru*d9LE+KA^LOI!q zl-6pXFhGa`Vxm6P6)I>XG;W{Q0K`@Vc?5y9Z3JBmbhIPbfwRjjEh}@w49u|d#F+U$ zA-X~9B~}Lko3!3mr;I$O4mHP1D%hopBHrv;b{tj^G6oDfL=VO^BW6L9zfxQ=eNWZN+w4K>AxsIa1Hk& zmk|nD8t@AqzApB&-(3{MDeia>!G@_s;JdwY=+fCUgrIqf0qdT;kXw?tYydn_5cgxV zoGkDl>Xd=>r!6nU0r>hQE`8H>^8h~ODI$sbKz$N`Z+VfAcyWrGAQ`-W*k4ZbWXSj1 bwx0SAm!&MbiCTV^00000NkvXXu0mjf^2^7Z literal 1 Icmd-A000XB3jhEB diff --git a/index.html b/index.html index 7862d38..d748d58 100644 --- a/index.html +++ b/index.html @@ -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]); diff --git a/lookup.php b/lookup.php index 553e8b1..b49293d 100644 --- a/lookup.php +++ b/lookup.php @@ -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");