maps-api-code-samples

Geoapify Location Platform Code Samples

License GitHub Repo Stars

Welcome to the Geoapify Location Platform Code Samples repository! This project provides a growing collection of code samples and demos showcasing how to work with Geoapify’s powerful geospatial APIs. Whether you’re building mapping applications, calculating routes, or integrating geocoding, these samples will help you get started quickly.

🧩 Available Code Samples

JavaScript

Node.js

Python


JavaScript: Printable Route Directions

What it does:
Generates printable, step-by-step route directions with static maps, interactive previews, and an elevation chart.

How it works:
Uses JavaScript and HTML to call the Geoapify Routing API for route data and the Static Maps API to render visual instructions. It includes an overview image of the full route, dynamic step previews with arrows, and an elevation profile.

Key features:

APIs used:

Demo:
👉 Printable Route Directions – Live Demo


JavaScript: Visualize Isochrones with Leaflet

What it does: Calculates and displays isochrone (travel-time) and isodistance (travel-distance) polygons on an interactive Leaflet map.

How it works: When a user clicks on the map, a form appears to select travel mode, isoline type, and range. The app requests isoline polygons from the Geoapify Isoline API, adds them to the map as GeoJSON layers, and places a custom marker at the origin.

Key features:

APIs used:

Demo: 👉 Leaflet Isochrone Demo – Live


JavaScript: Visualize Isochrones with MapLibre GL

What it does: Displays isochrone (time-based) and isodistance (distance-based) isolines on a MapLibre GL map using user-selected travel modes and values.

How it works: Users click on the map to choose a location, select parameters in a form, and the app requests an isoline from the Geoapify API. The result is styled and rendered as a colored polygon, with a custom marker showing the travel mode and range.

Key features:

APIs used:

Demo: 👉 MapLibre Isochrone Demo – Live


JavaScript: Route Elevation Profile with MapLibre

What it does: Calculates a route between two points and displays the turn-by-turn directions, travel stats, and an interactive elevation profile chart using MapLibre and Geoapify services.

How it works: Users define start and end locations by clicking on the map or typing addresses. The app uses the Geoapify Route Directions UI to calculate the route and fetch elevation data. The result is drawn on the map with markers and visualized with a Chart.js elevation profile.

Key features:

APIs used:

Demo: 👉 Route Elevation MapLibre Demo – Live


JavaScript: GPX Map Matching (Snap to Roads) with Geoapify & MapLibre GL

What it does: Takes GPS track data from a GPX file and snaps it to the road network based on travel mode (walking, driving, cycling). Displays both the original GPS trace and the snapped route on an interactive vector map, along with road attributes and summary details.

How it works: Uses JavaScript and HTML to load GPX files, convert them to GeoJSON using toGeoJSON, and simplify them for optimal API performance. The Geoapify Map Matching API aligns raw GPS points with real-world roads. Results are visualized using MapLibre GL with interactive popups for road attributes and options to download the matched route as GeoJSON or GPX.

Key features:

APIs used:

Demo: 👉 GPX Map Matching – Live Demo


JavaScript: Nearest Supermarkets by Driving Time

What it does:
Lets users click anywhere on the map to discover the nearest supermarkets (or any POI category) ranked by travel time instead of straight-line distance.

How it works:
Uses the Geoapify Places API to fetch candidate POIs, the Route Matrix API to calculate time/distance for each travel mode, and the Routing API plus MapLibre GL to visualize routes. A sidebar keeps the ranked list, hover states, and travel stats in sync with the map markers.

Key features:

APIs used:

Demo: 👉 Nearest Supermarkets by Driving Time – Live Demo


Node.js: Batch Geocoding with Rate Limiting

What it does:
Geocodes a large list of addresses while respecting API rate limits automatically.

How it works:
Reads addresses from a text file and sends geocoding requests to the Geoapify API using a built-in rate limiter. It ensures no more than 5 requests per second (Free plan limit), logs progress, and saves structured results to a JSON file.

Key features:

APIs used:


Node.js: Batch Reverse Geocoding

What it does:
Converts latitude/longitude pairs into human-readable addresses in batch mode, while respecting Geoapify API rate limits.

How it works:
Reads coordinate pairs from a text file and uses the Geoapify Reverse Geocoding API to resolve them into addresses. The script uses a built-in rate limiter to stay within 5 requests per second (Free plan limit) and saves the results in structured JSON.

Key features:

APIs used:


Node.js: Geocoding CLI from CSV with Retries

What it does: Performs batch geocoding of addresses from a CSV file using the Geoapify API, with support for retries and configurable output formats.

How it works: Reads structured address data from a CSV file, builds address strings based on configurable column mappings, and sends requests to the Geoapify Geocoding API. It uses a rate limiter to stay within Free plan limits and includes retry logic for failed requests. The tool works both as a CLI and as a Node.js module.

Key features:

APIs used:


Node.js: Reverse Geocoding CLI from CSV

What it does:
Reads a list of geographic coordinates from a CSV file and performs batch reverse geocoding using the Geoapify Reverse Geocoding API.

How it works:
Coordinates (lat, lon) are read from the CSV, then the script sends reverse geocoding requests with built-in rate limiting. It retries failed lookups and saves the output in NDJSON, JSON, or console format.

Key features:

APIs used:


Python: Create Map Example

What it does:
Generates an interactive web map using Geoapify map tiles and the Folium Python library.

How it works:
Uses Python and Folium to create a Leaflet-based map with custom tile styles from Geoapify. You can add interactive markers, control the map center and zoom, and export the result as an HTML file.

Key features:

APIs used:


Python: Batch Geocode Example

What it does:
Performs batch forward geocoding to convert addresses into geographic coordinates (latitude and longitude).

How it works:
Reads a list of addresses and sends them to the Geoapify Geocoding API. Optionally applies country filters to improve result relevance. Results are saved in NDJSON format for easy processing.

Key features:

APIs used:


Python: Reverse Geocode Example

What it does:
Converts latitude and longitude coordinates into human-readable addresses using batch reverse geocoding.

How it works:
Processes a list of coordinate pairs and sends them to the Geoapify Reverse Geocoding API. Supports optional country filtering and selectable output formats such as json or geojson.

Key features:

APIs used:


Python: Address Standardization Example

What it does:
Geocodes raw address data and generates standardized address strings based on a custom format.

How it works:
Processes a batch of addresses using the Geoapify Geocoding API and applies a formatting template with placeholders like {street}, {postcode}, and {city}. Supports both raw and clean outputs for different use cases.

Key features:

APIs used:


Python: Address Validation Example

What it does:
Validates address quality and accuracy using confidence levels from the Geoapify Geocoding API.

How it works:
Performs batch geocoding of address data and evaluates the rank.confidence and result_type fields to assess how well each address is recognized. Results are classified into confidence levels and saved to a CSV file.

Key features:

APIs used:


Python: Isoline Visualization Example

What it does:
Generates and visualizes travel areas (isochrones or isodistances) as interactive polygons on a map.

How it works:
Uses the Geoapify Isoline API to calculate reachable areas from a starting point, based on time or distance. The result is rendered on a Leaflet-based map with Folium and saved as an interactive HTML file.

Key features:

APIs used:


Python: Display Geocoded Addresses with Clustering and Confidence Coloring

What it does:
Displays geocoded address data on an interactive Folium map, with support for clustering, confidence-based color coding, and optional custom markers.

How it works:
Reads geocoded results from an NDJSON file and plots them on a Leaflet map using Folium. Nearby markers can be clustered, and each marker’s color reflects its confidence level. You can optionally use custom map marker icons from the Geoapify Marker API.

Key features:

APIs used:


Python: Fetch Places with Grid and Pagination

What it does:
Retrieves places of interest from the Geoapify Places API across a large geographic area using grid-based queries with pagination.

How it works:
Accepts a bounding box and optional filters, then divides the area into smaller 5×5 km grid cells. It queries each cell using the Places API with pagination and saves the results in NDJSON format. The script uses asyncio and aiohttp for efficient concurrent requests and respects the Free Plan rate limit.

Key features:

APIs used:


Python: Route Planner Result Processor

What it does:
Processes a request to the Geoapify Route Planner API, extracts results per agent, and visualizes their routes on interactive maps.

How it works:
Accepts a JSON file describing agents, jobs, and shipments. It sends the request to the Route Planner API, then organizes the results into per-agent folders. For each agent, it saves detailed route data and generates a route map using Folium and the Routing API. Unassigned or problematic jobs are logged separately.

Key features:

APIs used:

🚧 Upcoming Code Samples

We’re actively expanding this repository with examples in multiple programming languages, demonstrating how to work with additional Geoapify APIs and features.

Planned topics include:

Geocoding & Address Lookup

Isochrones API

POI Search API

Interactive & Static Maps

Multi-language Code Samples

🚀 How to Use

Each code sample includes everything you need to get started quickly:

🗺️ About Geoapify

Geoapify provides powerful and flexible APIs for building location-based and geospatial applications. Whether you’re working on maps, geocoding, routing, isochrones, POI search, or spatial analysis — Geoapify offers the tools to bring your ideas to life.

Our APIs are designed with developers in mind and are ideal for creating GIS platforms, logistics solutions, delivery systems, smart city tools, and more.

Explore our full API catalog at geoapify.com, or check out the API Playground to test requests in your browser.

💬 Feedback and Contributions

We welcome feedback, suggestions, and contributions to improve this repository!

If you have:

Feel free to contact us or open an issue or pull request.

Stay tuned — we’re continuously adding more examples and use cases!