Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Learn how to use visitor's location at the edge.
Geolocation in Edge Middleware is a Vercel example project that demonstrates how to read a visitor's location from the request object inside Next.js edge middleware using the geolocation helper from @vercel/functions.
This is a minimal Next.js example from Vercel's curated examples repository, built to show how edge middleware can access the geographic details of an incoming request. The template takes a Next.js request object and returns a structured set of location fields, including city, country, country flag emoji, the Vercel Edge Network region that handled the request, country region, latitude, and longitude. The project runs on Vercel's edge network and uses Tailwind CSS for styling.
geolocation helper — Import from @vercel/functions and call with the request to receive location data.pnpm create next-app --example and run with pnpm dev for local testing.edge-functions-geolocation.vercel.sh.The example deploys in two ways: one-click via the Vercel button, which creates a new project from the GitHub repository, or locally by running pnpm create next-app --example https://github.com/vercel/examples/tree/main/edge-middleware/geolocation geolocation. After starting with pnpm dev, the code imports geolocation from @vercel/functions, calls it with the incoming request, and logs the resulting location object.
