PHPackages                             b13/geocoding - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. b13/geocoding

ActiveTypo3-cms-extension[Utility &amp; Helpers](/categories/utility)

b13/geocoding
=============

Services for using geocoding from Google inside TYPO3 database records

6.0.0(1mo ago)1667.2k↓41.3%10[1 issues](https://github.com/b13/geocoding/issues)[1 PRs](https://github.com/b13/geocoding/pulls)GPL-2.0-or-laterPHPPHP ^8.2CI passing

Since Dec 14Pushed 1mo ago10 watchersCompare

[ Source](https://github.com/b13/geocoding)[ Packagist](https://packagist.org/packages/b13/geocoding)[ Docs](https://github.com/b13/t3ext-geocoding)[ RSS](/packages/b13-geocoding/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (5)Dependencies (4)Versions (13)Used By (0)

TYPO3 Extension: Geocoding
==========================

[](#typo3-extension-geocoding)

Provides services for querying Google Maps GeoCoding API v3 in your own extensions.

- Extension Key: geocoding
- Author: Benjamin Mack, b13 GmbH, 2012-2024
- Licensed under: GPLv2+
- Requires TYPO3 13+ and PHP 8.2 (see older versions of EXT:geocoding for support for previous TYPO3 versions)
- All code can be found and developed on github:

Introduction
------------

[](#introduction)

This extension provides an abstract way to get geo coordinates of addresses around the world. "Geocoding" let you fetch information about an address and stores it in the DB, by using the TYPO3 Caching Framework.

Installation
------------

[](#installation)

Use `composer req b13/geocoding` or install it via TYPO3's Extension Manager from the TYPO3 Extension Repository using the extension key `geocoding`.

Configuration
-------------

[](#configuration)

Fetch a Google API key () and add it to the extension configuration info in the Extension Manager. For more information see here:

How to use
----------

[](#how-to-use)

Inject the class in your TYPO3 extension. In the rare case, that you cannot use dependency injection, `GeneralUtility::makeInstance()` works as well.

GeoService
----------

[](#geoservice)

The extension provides the `GeoService`, a PHP service class to fetch latitude and longitude for a specific address string.

### GeoService-&gt;calculateCoordinatesForAllRecordsInTable

[](#geoservice-calculatecoordinatesforallrecordsintable)

If you need to query user input, a JavaScript API is probably the best way to do so. However, it can be done via PHP as well, by calling `GeoService->getCoordinatesForAddress($street, $zip, $city, $country)`

```
$coordinates = $this->geoServiceObject->getCoordinatesForAddress('Breitscheidstr. 65', 70176, 'Stuttgart', 'Germany');

```

The method also caches the result of the query.

### GeoService-&gt;calculateCoordinatesForAllRecordsInTable

[](#geoservice-calculatecoordinatesforallrecordsintable-1)

The method `GeoService->calculateCoordinatesForAllRecordsInTable($tableName, $latitudeField, $longitudeField, $streetField, $zipField, $cityField, $countryField, $addWhereClause)` allows you to bulk-encode latitude and longitude fields for existing addresses. The call can easily be built inside a Scheduler Task (see example below).

This way you can fetch the information about an address of a DB record (e.g. tt\_address) and store the data in the database table, given that you add two new fields latitude and longitude to that target table in your extension (no TCA information required for that).

### Example: Using GeoService as a Scheduler Task for tt\_address

[](#example-using-geoservice-as-a-scheduler-task-for-tt_address)

Put this into `EXT:my_extension/Classes/Task/GeocodingTask.php`:

```
