• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/text/geohash.php
  • Класс: BitrixMainTextGeoHash
  • Вызов: GeoHash::decode
static function decode($geohash)
{
	$base32DecodeMap = array_flip(static::$base32Chars);

	$latitudeInterval = static::$latitudeInterval;
	$longitudeInterval = static::$longitudeInterval;

	$isEven = true;
	$geohashLength = mb_strlen($geohash);
	for($i = 0; $i < $geohashLength; $i++)
	{
		if(!isset($base32DecodeMap[$geohash[$i]]))
		{
			throw new SystemException('This geo hash is invalid.');
		}
		$currentChar = $base32DecodeMap[$geohash[$i]];
		$bitsTotal = count(static::$bits);
		for($j = 0; $j < $bitsTotal; $j++)
		{
			$mask = static::$bits[$j];
			if($isEven)
			{
				if(($currentChar & $mask) !== 0)
				{
					$longitudeInterval[0] = ($longitudeInterval[0] + $longitudeInterval[1]) / 2;
				}
				else
				{
					$longitudeInterval[1] = ($longitudeInterval[0] + $longitudeInterval[1]) / 2;
				}
			}
			else
			{
				if(($currentChar & $mask) !== 0)
				{
					$latitudeInterval[0] = ($latitudeInterval[0] + $latitudeInterval[1]) / 2;
				}
				else
				{
					$latitudeInterval[1] = ($latitudeInterval[0] + $latitudeInterval[1]) / 2;
				}
			}
			$isEven = $isEven ? false : true;
		}
	}

	return array(
		($latitudeInterval[0] + $latitudeInterval[1]) / 2,
		($longitudeInterval[0] + $longitudeInterval[1]) / 2
	);
}