# Geocoding Augmentation

This data source connector provides detailed data for locations specified by their names, addresses, or coordinates.

**Before you start**

You need:

- **A table in Storage with the input:** one column with location names or addresses, or two columns with latitude and longitude. The sample files below work for a first test.
- **An API key for the provider,** unless you use `openstreetmap`, which needs none. Google Maps for Business needs a client ID and a private key instead. See Providers (#providers).

What each tab needs:

- **Prompt tab:** Kai, the **Kai Agent** button in the top bar, on supported stacks. A new Free Plan project has it from the start; elsewhere an organization admin turns it on once: Get started with Kai (/kai/getting-started/).
- **UI tab:** a browser.
- **CLI / API tab:** kbagent (/cli/getting-started/), connected to your project. The checks only read.

## Configuration
[Create a new configuration](https://help.keboola.com/components/configurations/#create-a-configuration) of the **Geocoding Augmentation** connector.

### Augment Locations
In this case, specify the location. The data source connector will fetch its geographical latitude and longitude 
using a specified [provider](https://help.keboola.com/components/extractors/other/geocoding-augmentation/#providers).
Specify one or more tables which have exactly one column with textual specification of the location. 
If the source table does not meet these requirements, 
edit the [input mapping](https://help.keboola.com/transformations/mappings/input/) details accordingly. 

You can test the extraction on this [sample file](https://help.keboola.com/components/extractors/other/geocoding-augmentation/locations.csv). 
Upload it to the `in.c-main` bucket in Storage first and call it `locations`.
Specify a single table in the [output mapping](https://help.keboola.com/transformations/mappings/output/) 
and select the **geocode** method in the configuration. You can use the `openstreetmap` provider for free.
(The names of the input and CSV files are arbitrary, and so are the names of the columns.)

![Screenshot - Add coordinates to locations](https://help.keboola.com/components/extractors/other/geocoding-augmentation/geocoding-1.png)

### Augment Coordinates
In this mode of operation, specify the geographical latitude and longitude. The connector
will then fetch information about the closest place found on the map of the given [provider](https://help.keboola.com/components/extractors/other/geocoding-augmentation/#providers).
Specify one or more tables which have exactly two columns; the first column with a latitude, the second 
one with a longitude. If the source table does not meet these requirements, edit the [input mapping](https://help.keboola.com/transformations/mappings/input/) details accordingly. 

You can test the extraction on this [sample file](https://help.keboola.com/components/extractors/other/geocoding-augmentation/coords.csv). 
Specify a single table in the [output mapping](https://help.keboola.com/transformations/mappings/output/), 
and select the **reverse** method in the configuration.
(The names of the input and CSV files are arbitrary, so are the names of the columns.) 

![Screenshot - Add locations to coordinates](https://help.keboola.com/components/extractors/other/geocoding-augmentation/geocoding-2.png)

Save the configuration and click **Run Component**.

**Check:**

#### Prompt

```text title="Prompt" wrap
Did the latest job of my Geocoding Augmentation configuration succeed, and how many rows and which columns does its output table have?
```

Kai only reads here, so it asks for no approval, and its answer links to what it found in your project.

#### UI

The job ends with status **Success** and the table in your output mapping has the results: latitude and
longitude for the **geocode** method, details of the closest place for the **reverse** method.

#### CLI / API

```bash
kbagent job list --component-id keboola.ag-geocoding --config-id 123456789 --limit 1
kbagent storage table-detail --table-id in.c-main.my-results
```

Replace `123456789` with your configuration ID and `in.c-main.my-results` with the table in your output mapping: `status` shows whether the job succeeded, and `columns` and `rows_count` show the results.

---

## Providers
In the component configuration, specify different providers of the location data. Usage limits and the result data may differ between various providers. 
Some of the providers require the `locale` parameter to be set. If you are unsure, leave it empty or use `us`. 
The following are the available providers that will be queried for the data:

- **google_maps** - [Google Maps](https://developers.google.com/maps/documentation/geocoding/intro) provider, needs parameter **apiKey** with your access key to the API (you need "Server" type of key).
- **google_maps_business** - [Google Maps](https://developers.google.com/maps/premium/faq#getting_started) for Business provider, needs parameters **clientId** and **privateKey**.
- **bing_maps** - [Bing Maps](https://docs.microsoft.com/en-us/bingmaps/spatial-data-services/geocode-dataflow-api/?redirectedfrom=MSDN) provider, needs attribute **apiKey**.
- **yandex** - [Yandex](https://tech.yandex.com/maps/geocoder/doc/desc/concepts/about-docpage/) provider, needs attribute apiKey; locale parameter may be one of these values: uk-UA, be-BY, en-US, en-BR, tr-TR.
- **map_quest** - [MapQuest](https://developer.mapquest.com/documentation/geocoding-api/) provider, needs parameter **apiKey**.
- **tomtom** - [TomTom](https://www.programmableweb.com/api/tomtom-geocoding) provider, needs parameter **apiKey**, parameter locale may have one of these values: de, es, fr, it, nl, pl, pt, sv.
- **opencage**: [OpenCage](https://opencagedata.com/) provider, needs parameter **apiKey**.
- **openstreetmap**: [OpenStreetMap](https://wiki.openstreetmap.org/wiki/Nominatim) provider, does not need any API key.
