mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-16 14:13:55 +00:00
Round the coordinates
This commit is contained in:
parent
b9a9c6bde3
commit
1b9fee043c
1 changed files with 11 additions and 5 deletions
|
@ -29,14 +29,20 @@ function geocoordinates_resolve_item(&$item) {
|
|||
if ($language == "")
|
||||
$language = "de";
|
||||
|
||||
$result = Cache::get("geocoordinates:".$language.":".$item["coord"]);
|
||||
$coords = explode(' ',$item["coord"]);
|
||||
|
||||
if (count($coords) < 2)
|
||||
return;
|
||||
|
||||
$coords[0] = round($coords[0], 5);
|
||||
$coords[1] = round($coords[1], 5);
|
||||
|
||||
$result = Cache::get("geocoordinates:".$language.":".$coords[0]."-".$coords[1]);
|
||||
if (!is_null($result)) {
|
||||
$item["location"] = $result;
|
||||
return;
|
||||
}
|
||||
|
||||
$coords = explode(' ',$item["coord"]);
|
||||
|
||||
$s = fetch_url("https://api.opencagedata.com/geocode/v1/json?q=".$coords[0].",".$coords[1]."&key=".$key."&language=".$language);
|
||||
|
||||
if (!$s) {
|
||||
|
@ -58,10 +64,10 @@ function geocoordinates_resolve_item(&$item) {
|
|||
|
||||
$item["location"] = $data->results[0]->formatted;
|
||||
|
||||
logger("Got location for coordinates ".$item["coord"].": ".$item["location"], LOGGER_DEBUG);
|
||||
logger("Got location for coordinates ".$coords[0]."-".$coords[1].": ".$item["location"], LOGGER_DEBUG);
|
||||
|
||||
if ($item["location"] != "")
|
||||
Cache::set("geocoordinates:".$language.":".$item["coord"], $item["location"]);
|
||||
Cache::set("geocoordinates:".$language.":".$coords[0]."-".$coords[1], $item["location"]);
|
||||
}
|
||||
|
||||
function geocoordinates_post_hook($a, &$item) {
|
||||
|
|
Loading…
Reference in a new issue