Insites Docs Developers guide Data and UsersDatabase ItemsUsing the GeoJSON Format for Geolocation

Using the GeoJSON Format for Geolocation

Last updated on June 26, 2024.

This guide will help you build a working site where you can find records in a maximum distance of X kilometres from given geo point coordinates.

GeoJSON is a geospatial data interchange format based on JSON for encoding various geographic data structures. It defines several types of JSON objects and how they are combined to represent data about geographic features, properties, and spatial extents.

The following geometry types are supported:

  • Point [long, lan]
  • LineString [[long, lan], [long, lan]]
  • Polygon [[[long, lan], [long, lan]]]
  • MultiPoint [[long, lan], [long, lan]]

Point [long, lan]

LineString [[long, lan], [long, lan]]

Polygon [[[long, lan], [long, lan]]]

MultiPoint [[long, lan], [long, lan]]

Read the official GeoJSON documentation to learn more.

Prerequisites

To understand this tutorial, you must have a good grasp of Database Tables, Database Items, Data Import/Export, and Forms.

Steps

Using the GeoJSON format to find all records at a maximum distance from geopoint coordinates is a four-step process:

  • Step 1: Create a database table
  • Step 2: Import data using GraphQL mutation
  • Step 3: Prepare GraphQL query
  • Step 4: Create a page

Step 1: Create a database table

Create :

Step 2: Import data using GraphQL mutation

Create a GraphQL mutation :

Create a :

Alternatively, you can create the record using a Form:

The HTML field snippet for geometry JSON is just a TextArea:

Note

This example is for presentation only. In a real-world scenario, no one provides raw JSON as a location address — there would be a JavaScript function using external geolocation services for getting coordinates, which then builds the required GeometryJSON structure.

Step 3: Prepare GraphQL query

Create the GraphQL query :

Step 4: Create a page

To wrap it up, create a page.

app/views/pages/search.liquid

Note

Since the argument has to be an Integer, and is a String, you have to cast this value to Integer. You can do this by appending a plus filter with a argument - adding a 0 converts a string into a number.

Have a suggestion for this page?

Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.