commit
c9898cf261
95 changed files with 5217 additions and 0 deletions
37
engines/maps/openstreetmap.php
Normal file
37
engines/maps/openstreetmap.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue