• Модуль: location
  • Путь к файлу: ~/bitrix/modules/location/lib/entity/location/converter/addressconverter.php
  • Класс: BitrixLocationEntityLocationConverterAddressConverter
  • Вызов: AddressConverter::convertToAddress
static function convertToAddress(EntityLocation $location): Address
{
	$type = $location->getType() === LocationType::UNKNOWN ? AddressFieldType::ADDRESS_LINE_2 : $location->getType();

	$result = (new Address($location->getLanguageId()))
		->setLatitude($location->getLatitude())
		->setLongitude($location->getLongitude())
		->setFieldValue($type, $location->getName());

	if($parents = $location->getParents())
	{
		/** @var Location $parent */
		foreach ($parents as $parent)
		{
			$result->setFieldValue($parent->getType(), $parent->getName());
		}
	}

	if($fields = $location->getAllFieldsValues())
	{
		foreach($fields as $type => $value)
		{
			if(!$result->isFieldExist($type))
			{
				$result->setFieldValue($type, $value);
			}
		}
	}

	return $result;
}