Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Implementing Nearby Search with Redis GEO in a NestJS Backend

This tutorial demonstrates how to use Redis' GEO data structure together with Docker, RedisInsight, and a NestJS backend to store location data, perform distance calculations and radius searches, and finally display nearby points on a web map using AMap and Axios.

The article explains that many location‑based features such as ride‑hailing, shared power banks, hotels, and nearby people are implemented using Redis GEO, which stores geographic coordinates and supports distance and radius queries.

First, Docker Desktop is used to run a Redis container, exposing port 6379 and mounting a data volume. RedisInsight is then installed to visualize keys.

Next, a NestJS project is created ( npm i -g @nestjs/cli && nest new nearby-search) and the redis client library is added. A RedisModule provides a REDIS_CLIENT provider that connects to the local Redis instance, and a RedisService wraps geoAdd, geoPos, geoList, and geoSearch methods using the Redis client.

The AppController injects RedisService and defines routes: GET /addPos?name=...&longitude=...&latitude=... – adds a point. GET /allPos – lists all points. GET /pos?name=... – retrieves a point's coordinates. GET /nearbySearch?longitude=...&latitude=...&radius=... – searches points within a radius (km).

After adding several sample locations (e.g., Tiananmen, Cultural Palace), the distance between points is verified with GEODIST, and radius queries demonstrate how the search radius affects results.

For the frontend, a static public/index.html is served, loading the AMap JavaScript SDK. A map is initialized centered on a sample coordinate, and markers and circles are added to illustrate points.

Axios is then used to call the /nearbySearch API, retrieve nearby points, and dynamically create AMap markers for each result, drawing a circle representing the search radius.

The final result shows a working end‑to‑end system where a NestJS backend stores location data in Redis GEO, provides APIs for adding and querying points, and a web page visualizes nearby points on a map.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

BackenddockerRedisAmapNestJSGEOLocation Search

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion