mirror of
https://git.bakhai.co.in/FbIN/LibreY.git
synced 2025-11-05 04:21:31 +05:30
37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
require_once "engines/text/text.php";
|
|
class OSMRequest extends EngineRequest {
|
|
public function get_request_url() {
|
|
|
|
$query_encoded = str_replace("%22", "\"", urlencode($this->query));
|
|
$results = array();
|
|
|
|
// TODO allow the nominatim instance to be customised
|
|
$url = "https://nominatim.openstreetmap.org/search?q=$query_encoded&format=json";
|
|
|
|
return $url;
|
|
}
|
|
|
|
|
|
public function parse_results($response) {
|
|
$json_response = json_decode($response, true);
|
|
if (!$json_response)
|
|
return array();
|
|
|
|
$results = array();
|
|
foreach ($json_response as $item) {
|
|
array_push($results, array(
|
|
"title" => $item["name"],
|
|
"description" => $item["display_name"],
|
|
"url" => "https://www.openstreetmap.org/" . $item["osm_type"] . "/" . $item["osm_id"],
|
|
"base_url" => "www.openstreetmap.org"
|
|
));
|
|
}
|
|
return $results;
|
|
}
|
|
|
|
public static function print_results($results, $opts) {
|
|
TextSearch::print_results($results, $opts);
|
|
}
|
|
}
|
|
?>
|