30/01
2018
Wallogit.com
2017 © Pedro PelĆ”ez
Class libraries implemented using PHP based on GeoHash algorithms.
Class libraries implemented using PHP based on GeoHash algorithms., (*1)
For details, please refer to the blog ļ¼Chineseļ¼:, (*2)
https://usblog.crazylaw.cn/index.php/archives/324/, (*3)
Three API methods are provided., (*4)
around($lng, $lat, $interceptLength = 0) Convert the HashCode in the 9 regions of the longitude and latitude., (*5)
encode($lng, $lat, $interceptLength = 0) Converts HashCode to the specified latitude and longitude., (*6)
distance($centerLng, $centerLat, $pointLng, $pointLat, $lenType = 1, $decimal = 2) Calculate the distance between two latitude and longitude., (*7)
exampleļ¼, (*8)
require_once 'vendor/autoload.php';
// The base hashcode length must be a multiple of 5, otherwise it will automatically be filled to a multiple of 5.
// The longer the base length of hashcode is, the more options are available to intercept, and the longer it is recommended. 10 is usually enough.
$hashCodeLength = 10;
$geohash = new ccinn\GeoHash($hashCodeLength);
// Search nearby 20 meters
$interceptLength = 8;
$around = $geohash->around(113.314748, 23.125851, $interceptLength);
var_dump($around, $point = $geohash->encode(113.314851, 23.125839, $interceptLength));
if (in_array($point, $around)) {
echo 'in_around' . PHP_EOL;
} else {
echo 'not_in_around' . PHP_EOL;
}
var_dump('distance:' . $geohash->distance(113.314748, 23.125851, 113.314851, 23.125839) . 'm');