1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
bycoordsconverter.php
См. документацию.
1<?php
2
3namespace Bitrix\Location\Source\Google\Converters;
4
5use Bitrix\Location\Entity\Address\FieldType;
6use Bitrix\Location\Entity\Location;
7use Bitrix\Location\Entity\Generic\Collection;
8use Bitrix\Location\Exception\RuntimeException;
9use Bitrix\Location\Source\Google;
10
17{
22 public function convert(array $data)
23 {
24 if (isset($data['status']) && $data['status'] !== 'OK')
25 {
26 $errorMessage = $data['error_message'] . ' ('.$data['status'] . ')' ?? $data['status'];
27
29 }
30
31 if (!isset($data['results']) || !is_array($data['results']))
32 {
33 return null;
34 }
35
36 $result = new Collection;
37
38 foreach ($data['results'] as $item)
39 {
40 if (isset($item['types']))
41 {
42 $type = $this->convertTypes($item['types'], Location\Type::class);
43 }
44 else
45 {
46 $type = FieldType::UNKNOWN;
47 }
48
49 $location = (new Location())
50 ->setSourceCode(Google\Repository::getSourceCode())
51 ->setExternalId($item['place_id'])
52 ->setLongitude($item['geometry']['location']['lng'])
53 ->setLatitude($item['geometry']['location']['lat'])
54 ->setType($type)
55 ->setLanguageId($this->languageId);
56
57
58 if (is_array($item['address_components']))
59 {
60 if ($address = $this->createAddress($item['address_components']))
61 {
62 $address->setLatitude($location->getLatitude());
63 $address->setLongitude($location->getLongitude());
64 $location->setAddress($address);
65
66 if ($address->isFieldExist(FieldType::POSTAL_CODE))
67 {
68 $location->setFieldValue(
69 Location\FieldType::POSTAL_CODE,
70 $address->getFieldValue(FieldType::POSTAL_CODE)
71 );
72 }
73 }
74
75 if ($address->isFieldExist($type))
76 {
77 $location->setName($address->getFieldValue($type));
78 }
79 }
80
81 if ($location->getName() === '')
82 {
83 $location->setName($item['formatted_address']);
84 }
85
86 $result->addItem($location);
87 }
88
89 return $result;
90 }
91}
$type
Определения options.php:106
createAddress(array $addressComponents)
Определения baseconverter.php:67
convertTypes(array $types, string $typesClass)
Определения baseconverter.php:44
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage
$location
Определения options.php:2729