> For the complete documentation index, see [llms.txt](https://codemash.gitbook.io/codemash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codemash.gitbook.io/codemash/cloud/database/schema/field-types/geolocation.md).

# Geolocation

A GeoJSON point (or points): an object { type, coordinates } with longitude and latitude checked by the server.

A **Geo Location** field stores a point on the map as GeoJSON: `{ "type": "Point", "coordinates": [longitude, latitude] }`. The schema lists which geometry types are allowed; the server checks the pair and its range.

**Builder:** Form fields panel → **Geo Location** · widget `geo_location` · data type `geolocation.schema.v1`

## Data schema

```json
{
  "location": {
    "type": "object",
    "properties": {
      "type": { "type": "string", "enum": ["Point"] },
      "coordinates": { "type": "array", "items": { "type": "number" } }
    }
  }
}
```

| Keyword                  | Required | What it does                                                 | Example     |
| ------------------------ | -------- | ------------------------------------------------------------ | ----------- |
| `type`                   | yes      | Always `"object"`.                                           | `"object"`  |
| `properties.type.enum`   | yes      | The geometry kinds allowed: `Point`, `MultiPoint`, or both.  | `["Point"]` |
| `properties.coordinates` | yes      | Always `{ "type": "array", "items": { "type": "number" } }`. |             |

### What the server refuses

Every write — insert, update, replace; from Cloud, the API, an SDK, the CLI or an AI agent — is checked against the published schema. A broken value is answered with one error per field: the code, and `Field '<name>' is invalid: <reason>`. Nothing is written.

| Case                                                           | Code                     | The reason it gives                                                                                                              |
| -------------------------------------------------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
| a required field is missing or `null`                          | `CM-ERRORS-DATABASE-030` | `a value is required`                                                                                                            |
| not an object with `type` and `coordinates`                    | `CM-ERRORS-DATABASE-039` | `must be a geolocation object {"type": "Point", "coordinates": [longitude, latitude]}`                                           |
| `type` is not a string                                         | `CM-ERRORS-DATABASE-039` | `the geometry type must be a string`                                                                                             |
| a geometry type outside the list                               | `CM-ERRORS-DATABASE-045` | `geometry type 'Polygon' is not one of: Point`                                                                                   |
| `coordinates` is not a `[longitude, latitude]` pair of numbers | `CM-ERRORS-DATABASE-048` | `coordinates must be a [longitude, latitude] pair of numbers`                                                                    |
| longitude or latitude out of the world's range                 | `CM-ERRORS-DATABASE-048` | `longitude 200 must be between -180 and 180` / `latitude 95 must be between -90 and 90`                                          |
| a MultiPoint without pairs                                     | `CM-ERRORS-DATABASE-048` | `MultiPoint coordinates must be an array of [longitude, latitude] pairs` / `… must hold at least one [longitude, latitude] pair` |
| a declared member is missing or an extra one is sent           | `CM-ERRORS-DATABASE-047` | `the 'coordinates' member is required` / `unknown member 'altitude' (allowed: type, coordinates)`                                |

A keyword that is not in the table above is refused when the schema is **saved**, not when a record is written: `CM-ERRORS-SCHEMA-010` — `Data schema violates meta-schema: Property 'sort' has not been defined and the schema does not allow additional properties. Path 'properties.location.sort' (field 'properties.location' checked as geolocation.schema.v1).`

## UI schema

The cell uses the `geo_location` widget: a Longitude and a Latitude input (and a clear button).

```json
{
  "colSpan": 6,
  "element": {
    "fieldId": "location",
    "meta": { "widget": "geo_location", "label": "Location" }
  }
}
```

Every cell also takes the common layout options: `label`, `placeholder`, `help` (the text under the input), `required`, `readonly` and `hidden`. Keys outside this list — `watermark`, `hint`, `permissions` — are refused when the schema is saved (`CM-ERRORS-SCHEMA-012`), see [Schema authoring guide](/codemash/cloud/database/schema.md#one-contract-no-second-dialect).

<figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-bcf26f7d9372841fb5f83e4ed37825abe1941052%2Ffield-types-dates-1.png?alt=media" alt="The Dates, flags &#x26; places tab of the all-types record form with Geolocation cells, each a Longitude input, a Latitude input and a clear button"><figcaption><p>geo_location cells on the Dates, flags &#x26; places tab.</p></figcaption></figure>

## Records

A record the schema accepts:

```json
{ "location": { "type": "Point", "coordinates": [25.2797, 54.6872] } }
```

A record it refuses:

```json
{ "location": { "type": "Point", "coordinates": [200, 54.6872] } }
```

The answer: `CM-ERRORS-DATABASE-048` — `Field 'location' is invalid: longitude 200 must be between -180 and 180`. In Cloud the same sentence is shown under the field before the form is sent; the server repeats the check on every API write.

## Good to know

* Longitude first, latitude second — the GeoJSON order, which is the opposite of "lat, long" in most map apps. The form labels the inputs, the API does not.
* A [nested form](/codemash/cloud/database/schema/field-types/nested-form.md) may not declare the members `type` + `coordinates` together — that shape *is* the geolocation type.
* Create a `2dsphere` index on the field to run `$near` queries; see [Records list columns and index warnings](/codemash/cloud/database/collections/schema-indexes.md).

## Do it from code

```ts
await norbix.api.database.insertOne({
  collectionName: 'places',
  document: JSON.stringify({ location: { type: 'Point', coordinates: [25.2797, 54.6872] } }),
});
```

```sh
norbix api database one insert --collectionName places --document '{"location":{"type":"Point","coordinates":[25.2797,54.6872]}}'
```

The client setup is on the [Database page](/codemash/cloud/database.md#use-it-from-code). API: [Insert One](/codemash/api-reference/database/collections/insert-one.md) · [Save Database Schema](/codemash/api-reference/database/schemas/save-database-schema.md)

## Related

[Nested form](/codemash/cloud/database/schema/field-types/nested-form.md) · [Filter](/codemash/cloud/concepts/search-parameters/filter.md) · [Field type reference](/codemash/cloud/database/schema/field-types.md) · [Schema authoring guide](/codemash/cloud/database/schema.md) · [Create a schema](/codemash/cloud/database/collections/create-schema.md)
