25 if(isset($data[
'status']) && $data[
'status'] !==
'OK')
27 $errorMessage = $data[
'error_message'].
' ('.$data[
'status'].
')' ?? $data[
'status'];
31 if(!isset($data[
'result']))
36 $data = $data[
'result'];
38 if(isset($data[
'types']) && is_array($data[
'types']))
44 $type = Location\Type::UNKNOWN;
49 ->setExternalId((
string)$data[
'place_id'])
50 ->setName((
string)$data[
'name'])
51 ->setLongitude((
string)$data[
'geometry'][
'location'][
'lng'])
52 ->setLatitude((
string)$data[
'geometry'][
'location'][
'lat'])
54 ->setLanguageId($this->languageId);
56 if(is_array($data[
'address_components']))
58 if ($address = $this->
createAddress($data[
'address_components']))
60 $address->setLatitude($result->getLatitude());
61 $address->setLongitude($result->getLongitude());
62 $result->setAddress($address);
64 if($address->isFieldExist(FieldType::POSTAL_CODE))
66 $result->setFieldValue(
67 FieldType::POSTAL_CODE,
68 $address->getFieldValue(FieldType::POSTAL_CODE)
72 if(!$address->isFieldExist(FieldType::ADDRESS_LINE_2) && $type === Location\Type::UNKNOWN)
74 $address->setFieldValue(FieldType::ADDRESS_LINE_2, (
string)$data[
'name']);