Add API to convert between coordinates and a 4-word phrase, add PlusCodes to reverse geocoder

master
Skylar Ittner 3 years ago
parent 3a670076ce
commit e03c02d416

@ -27,6 +27,14 @@ $APIS = [
"longitude" => "/\-?[0-9]{1,3}(\.[0-9]{0,10})?/"
]
],
"gis/fixphrase" => [
"load" => "gis.fixphrase.php",
"vars" => [
"words (optional)" => "",
"latitude (optional)" => "/\-?[0-9]{1,3}(\.[0-9]{0,10})?/",
"longitude (optional)" => "/\-?[0-9]{1,3}(\.[0-9]{0,10})?/"
]
],
"gis/geoip" => [
"load" => "net.geoip.php",
"vars" => [

@ -4,6 +4,7 @@
"io-developer/php-whois": "^4.0",
"geoip2/geoip2": "^2.11",
"shippo/shippo-php": "^1.4",
"easypost/easypost-php": "^3.5"
"easypost/easypost-php": "^3.5",
"bogdaan/open-location-code": "dev-master"
}
}

57
composer.lock generated

@ -4,8 +4,59 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "e99006318711be4bc8b61a3e909a24da",
"content-hash": "56a7b51650928bd0c6c4eb301df2ccd9",
"packages": [
{
"name": "bogdaan/open-location-code",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/Bogdaan/open-location-code.git",
"reference": "6e384e41cc6d6dd4d87f95c36aabf0de5256bf3f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Bogdaan/open-location-code/zipball/6e384e41cc6d6dd4d87f95c36aabf0de5256bf3f",
"reference": "6e384e41cc6d6dd4d87f95c36aabf0de5256bf3f",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"psr/log": "~1.0"
},
"default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
"OpenLocationCode\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Novikov Bogdan",
"email": "hcbogdan@gmail.com",
"homepage": "http://hcbogdan.com"
}
],
"description": "Open location code for php",
"keywords": [
"olc",
"open location code",
"plus.codes"
],
"support": {
"issues": "https://github.com/Bogdaan/open-location-code/issues",
"source": "https://github.com/Bogdaan/open-location-code/tree/master"
},
"time": "2018-02-03T16:15:27+00:00"
},
{
"name": "catfan/medoo",
"version": "v2.0.1",
@ -634,7 +685,9 @@
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"stability-flags": {
"bogdaan/open-location-code": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],

@ -0,0 +1,46 @@
<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
$output = [];
try {
if (!empty($VARS["words"])) {
// convert words to coordinates
$words = urldecode($VARS["words"]);
$coords = FixPhrase::decode($words);
$output = [
"status" => "OK",
"action" => "decodeFromWords",
"words" => $words,
"coords" => $coords
];
} else if (!empty($VARS["latitude"]) && !empty($VARS["longitude"])) {
// convert coordinates to words
$lat = round($VARS["latitude"], 4);
$lon = round($VARS["longitude"], 4);
$words = FixPhrase::encode($lat, $lon);
$output = [
"status" => "OK",
"action" => "encodeToWords",
"words" => $words,
"coords" => [
$lat,
$lon
]
];
} else {
throw new Exception("Must supply either a string of words or a latitude/longitude pair.");
}
} catch (Exception $ex) {
sendJsonResp($ex->getMessage(), "ERROR");
}
exitWithJson($output);

@ -6,11 +6,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
use OpenLocationCode\OpenLocationCode;
$output = [];
$lat = round($VARS["latitude"], 6);
$lon = round($VARS["longitude"], 6);
$lat = round($VARS["latitude"], 5);
$lon = round($VARS["longitude"], 5);
$cacheresp = $memcache->get("gis.geocode.reverse.$lat,$lon");
if ($cacheresp !== false) {
@ -33,10 +34,12 @@ $output = [
"country" => $location['adminArea1'],
"postalCode" => $location['postalCode']
],
"pluscode" => OpenLocationCode::encode($lat, $lon),
"fixphrase" => FixPhrase::encode($lat, $lon),
"coords" => [
$lat,
$lon
]
],
];
$memcache->set("gis.geocode.reverse.$lat,$lon", json_encode($output));

File diff suppressed because it is too large Load Diff

Binary file not shown.
Loading…
Cancel
Save