Geopoint
Schema type reference for the geopoint type.
An object signifying a global latitude/longitude/altitude coordinate. Longitude and latitude are stored as decimal degrees, while altitude is stored as a floating point representing meters above sea level. See the GeopointDefinition reference for the full type definition.
Properties
Requiredtype
Value must be set to
geopoint.Requiredname
The field name. This becomes the key in the document.
Human-readable label for the field.
If set to
true, this field is hidden in the studio. You can also supply a callback function to make it a conditional field.If set to
true, this field is not editable in the studio. You can also supply a callback function to make it a conditional field.Short description for editors of how the field is to be used.
The initial value used when creating new values of this type. Can be a literal value, or a resolver function that returns a literal value or a promise that resolves to one.
Lets you provide custom components to override the studio defaults in various contexts. The available keys are
annotation,block,diff,field,inlineBlock,input,item, andpreview.Marks a field or document type as deprecated in the studio interface and displays a user-defined message set through the single required
reasonproperty.If you deploy a GraphQL API schema, this property is translated into the
@deprecateddirective.Supply a custom icon for this field. See the icons documentation for more information.
options
Object
Visual options for the geopoint field in the studio. See the full list available in the GeopointOptions type.
Validation (GeopointRule)
Ensures that this field exists.
Discards the validation rules set before it in the chain and makes the field optional. Rules chained after it still apply.
Creates a custom validation rule.
Sets the level of this rule chain to error, with an optional custom message.
Sets the level of this rule chain to warning, with an optional custom message. Warnings do not prevent publishing.
Sets the level of this rule chain to info, with an optional custom message. Info messages are purely informational and do not prevent publishing.
Gets the value of a sibling field to use in validation. Useful for creating validation rules that depend on the value of another field.
import {defineField, defineType} from 'sanity'
export const launchpad = defineType({
name: 'launchpad',
type: 'document',
fields: [
defineField({
title: 'Launchpad Location',
name: 'location',
type: 'geopoint',
}),
],
}){
"_type": "launchpad",
"location": {
"_type": "geopoint",
"lat": 58.63169011423141,
"lng": 9.089101352587932,
"alt": 13.37
},
...
}While the geopoint type is available in Sanity by default, you will probably want to install a plugin that provides a more visual way to input the coordinates. For instance, you could use the @sanity/google-maps-input plugin:
npm install @sanity/google-maps-inputpnpm add @sanity/google-maps-inputyarn add @sanity/google-maps-inputbun add @sanity/google-maps-inputThen add the plugin to your sanity.config.ts|js. The example reads your Google Maps API key from the SANITY_STUDIO_GOOGLE_MAPS_API_KEY environment variable:
import {defineConfig} from 'sanity'
import {googleMapsInput} from '@sanity/google-maps-input'
export default defineConfig({
// ...
plugins: [
googleMapsInput({
apiKey: process.env.SANITY_STUDIO_GOOGLE_MAPS_API_KEY ?? '',
}),
],
})Make sure the key has access to all of the following APIs:
- Google Maps JavaScript API
- Google Places API (New)
- Google Static Maps API
To create a key and enable the APIs, follow Google's Set up the Maps JavaScript API guide.
Gotcha
Restrict your API key. The plugin uses the key in the browser, so anyone who can open your studio can read it, even when the key comes from an environment variable or your repository is private. In the Google Cloud console, restrict the key to your studio's URLs (HTTP referrers) and to the Maps JavaScript API, Places API (New), and Static Maps API.
Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?