Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Geospatial Queries / Field

default discord avatar
wiesson2 years ago
1 1

Does PayloadCMS supports geospatial queries? (https://www.mongodb.com/docs/manual/geospatial-queries/). I'd like to create a custom field that gets lat/lng from an autocompleted address.

Goal: I want to find database entries according to a radius around a point or within a geofence and show them on my website. (For example, show related entries that are nearby)

  • Selected Answer
    discord user avatar
    DanRibbens
    2 years ago

    Great question! Look at the docs for the point field.

    https://payloadcms.com/docs/fields/point

    Based on what you said it should get you everything you need.

    3 replies
  • default discord avatar
    wiesson2 years ago

    Not sure how I could miss that 😅

  • default discord avatar
    wiesson2 years ago

    Btw, any hint (or even better an example), how I could create a custom field that loads data from an API endpoint (based on input) and renders a select field for the addresses?

    Something like this (example taken from graphcms)
    Screenshot 2022-07-03 at 07 38 07

    (I have a react component ready that loads google maps sdk, has an input field, etc...)

    // edit:

    Just found https://github.com/payloadcms/custom-field-guide and https://github.com/payloadcms/public-demo/tree/master/src/fields to look at 👀

  • discord user avatar
    DanRibbens
    2 years ago

    You got it. The ui field is useful if you don't have data directly on the field and want to show a custom element in the edit view and/or cell views.

    When you do have data to store on the field, you can use whatever field type is best reflected by the data and still write your own custom components as explained in that guide. The main difference is having to update values. UI fields are nice in that you don't have to set values and can just get other field data to display what you need.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team..