Handle non-phrase search box input by running geocode lookup
This commit is contained in:
parent
b21986f947
commit
625fcf721f
BIN
favicon.ico
BIN
favicon.ico
Binary file not shown.
Before Width: | Height: | Size: 1 B After Width: | Height: | Size: 901 B |
15
index.html
15
index.html
@ -272,6 +272,21 @@
|
|||||||
function dolookup(words) {
|
function dolookup(words) {
|
||||||
try {
|
try {
|
||||||
words = words.trim().toLowerCase().replace(/\s+/g, ' ');
|
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);
|
var coords = FixPhrase.decode(words);
|
||||||
|
|
||||||
showLocationPopup(coords[0], coords[1], coords[3], coords[2]);
|
showLocationPopup(coords[0], coords[1], coords[3], coords[2]);
|
||||||
|
15
lookup.php
15
lookup.php
@ -57,8 +57,21 @@ try {
|
|||||||
$lon
|
$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 {
|
} 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) {
|
} catch (Exception $ex) {
|
||||||
sendJsonResp($ex->getMessage(), "ERROR");
|
sendJsonResp($ex->getMessage(), "ERROR");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user