Loading...

Geographical search

Once a visitor has found a film, the natural next question is "where can I watch it near me?". For that you need location. Let's add a cinemas list and let visitors find the nearest ones — "showing within 2 miles".

Coordinates fields

To search by distance, each record needs a location: a latitude and longitude. You add these with a coordinates field, a special field type that turns on geographic search for the list. Once a list has coordinates, every result can be searched by how close it is to a point, and every result comes back with a distance.

Build the cinemas list

Create a new list called cinemas. Open it, choose Fields, then Add Coordinates — that's all it takes to enable location. Each record now has a Latitude and Longitude to fill in:

Adding a cinema with latitude and longitude fields

You can add cinemas by hand, but it's quicker to upload them. Put a latitude and longitude on each record in your file and Search Stack maps them to the location automatically:

[
  { "name": "Odeon Leicester Square", "city": "London", "latitude": 51.5106, "longitude": -0.1301 },
  { "name": "BFI IMAX",               "city": "London", "latitude": 51.5049, "longitude": -0.1140 }
]

After importing, the list shows each cinema's coordinates and a distance column:

The cinemas list showing name, city, coordinates and distance columns

Find what's nearby

A geographic search adds a radius to a normal search. Its value is latitude,longitude,distance — the point to search around, and how far. This finds cinemas within 2 miles of a visitor standing in central London:

GET https://api.searchstack.dev/search/Demo/cinemas/1?radius=51.5074,-0.1278,2mi
X-API-Key: {your key}

Results come back closest first, each with its distance from that point:

{
  "results": [
    { "name": "Odeon Leicester Square", "distance": 0.3, "fields": { "city": "London" } },
    { "name": "Curzon Soho",            "distance": 0.4, "fields": { "city": "London" } },
    { "name": "Picturehouse Central",   "distance": 0.5, "fields": { "city": "London" } }
  ],
  "count": 3,
  "total_count": 3
}

Radius combines with everything else you've built. You can search text and filter and restrict by distance in one request — "cinemas called 'Odeon' within 5 miles" is just a query plus a radius. Get a visitor's location from the browser's geolocation and you have "showing near you" with no map service to wire up.

That's the backend done: searchable, filterable, grouped, self-improving, and location-aware. The last page puts a real search box on a page — the part your visitors actually see.

Coordinates fields and the radius grammar are covered in the Fields reference.

« User Generated Suggestions
Next — Components »
Drop the finished search box onto a page.
Top