4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
13 namespace Civi\Api4\Action\Address
;
15 use Civi\Api4\Generic\Result
;
18 * Converts an address string to lat/long coordinates.
20 * @method $this setAddress(string $address)
21 * @method string getAddress()
23 class GetCoordinates
extends \Civi\Api4\Generic\AbstractAction
{
26 * Address string to convert to lat/long
33 public function _run(Result
$result) {
34 $coord = \CRM_Utils_Geocode_Google
::getCoordinates($this->address
);
35 if (isset($coord['geo_code_1'], $coord['geo_code_2'])) {
38 elseif (!empty($coord['geo_code_error'])) {
39 throw new \
API_Exception('Geocoding failed. ' . $coord['geo_code_error']);