1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
geohash.php
См. документацию.
1
<?php
2
namespace
Bitrix\Main\Text;
3
4
5
use Bitrix\Main\SystemException;
6
7
class
GeoHash
8
{
9
const
MAX_LENGTH
= 15;
10
11
protected
static
$latitudeInterval
=
array
(-90.0, 90.0);
12
protected
static
$longitudeInterval
=
array
(-180.0, 180.0);
13
protected
static
$bits
=
array
(16, 8, 4, 2, 1);
14
protected
static
$base32Chars
=
array
(
15
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
16
'h'
,
'j'
,
'k'
,
'm'
,
'n'
,
'p'
,
'q'
,
'r'
,
's'
,
't'
,
'u'
,
'v'
,
'w'
,
'x'
,
'y'
,
'z'
17
);
18
19
public
static
function
encode
(
array
$coordinate, $length = self::MAX_LENGTH)
20
{
21
$latitudeInterval
= static::$latitudeInterval;
22
$longitudeInterval
= static::$longitudeInterval;
23
24
$isEven =
true
;
25
$bit = 0;
26
$charIndex = 0;
27
28
$geohash =
''
;
29
30
while
(mb_strlen($geohash) < $length)
31
{
32
if
($isEven)
33
{
34
$middle = (
$longitudeInterval
[0] +
$longitudeInterval
[1]) / 2;
35
if
($coordinate[1] > $middle)
36
{
37
$charIndex |= static::$bits[$bit];
38
$longitudeInterval
[0] = $middle;
39
}
40
else
41
{
42
$longitudeInterval
[1] = $middle;
43
}
44
}
45
else
46
{
47
$middle = (
$latitudeInterval
[0] +
$latitudeInterval
[1]) / 2;
48
if
($coordinate[0] > $middle)
49
{
50
$charIndex |= static::$bits[$bit];
51
$latitudeInterval
[0] = $middle;
52
}
53
else
54
{
55
$latitudeInterval
[1] = $middle;
56
}
57
}
58
if
($bit < 4)
59
{
60
$bit++;
61
}
62
else
63
{
64
$geohash .= static::$base32Chars[$charIndex];
65
$bit = 0;
66
$charIndex = 0;
67
}
68
$isEven = $isEven ?
false
:
true
;
69
}
70
71
return
$geohash;
72
}
73
74
public
static
function
decode
($geohash)
75
{
76
$base32DecodeMap = array_flip(static::$base32Chars);
77
78
$latitudeInterval
= static::$latitudeInterval;
79
$longitudeInterval
= static::$longitudeInterval;
80
81
$isEven =
true
;
82
$geohashLength = mb_strlen($geohash);
83
for
(
$i
= 0;
$i
< $geohashLength;
$i
++)
84
{
85
if
(!isset($base32DecodeMap[$geohash[
$i
]]))
86
{
87
throw
new
SystemException
(
'This geo hash is invalid.'
);
88
}
89
$currentChar = $base32DecodeMap[$geohash[
$i
]];
90
$bitsTotal =
count
(static::$bits);
91
for
($j = 0; $j < $bitsTotal; $j++)
92
{
93
$mask = static::$bits[$j];
94
if
($isEven)
95
{
96
if
(($currentChar & $mask) !== 0)
97
{
98
$longitudeInterval
[0] = (
$longitudeInterval
[0] +
$longitudeInterval
[1]) / 2;
99
}
100
else
101
{
102
$longitudeInterval
[1] = (
$longitudeInterval
[0] +
$longitudeInterval
[1]) / 2;
103
}
104
}
105
else
106
{
107
if
(($currentChar & $mask) !== 0)
108
{
109
$latitudeInterval
[0] = (
$latitudeInterval
[0] +
$latitudeInterval
[1]) / 2;
110
}
111
else
112
{
113
$latitudeInterval
[1] = (
$latitudeInterval
[0] +
$latitudeInterval
[1]) / 2;
114
}
115
}
116
$isEven = $isEven ?
false
:
true
;
117
}
118
}
119
120
return
array
(
121
(
$latitudeInterval
[0] +
$latitudeInterval
[1]) / 2,
122
(
$longitudeInterval
[0] +
$longitudeInterval
[1]) / 2
123
);
124
}
125
}
Bitrix\Main\SystemException
Определения
SystemException.php:9
Bitrix\Main\Text\GeoHash
Определения
geohash.php:8
Bitrix\Main\Text\GeoHash\decode
static decode($geohash)
Определения
geohash.php:74
Bitrix\Main\Text\GeoHash\$base32Chars
static $base32Chars
Определения
geohash.php:14
Bitrix\Main\Text\GeoHash\MAX_LENGTH
const MAX_LENGTH
Определения
geohash.php:9
Bitrix\Main\Text\GeoHash\encode
static encode(array $coordinate, $length=self::MAX_LENGTH)
Определения
geohash.php:19
Bitrix\Main\Text\GeoHash\$latitudeInterval
static $latitudeInterval
Определения
geohash.php:11
Bitrix\Main\Text\GeoHash\$longitudeInterval
static $longitudeInterval
Определения
geohash.php:12
Bitrix\Main\Text\GeoHash\$bits
static $bits
Определения
geohash.php:13
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
false
return false
Определения
prolog_main_admin.php:185
$i
$i
Определения
factura.php:643
count
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения
waybill.php:936
bitrix
modules
main
lib
text
geohash.php
Создано системой
1.14.0