Command Palette

Search for a command to run...

YepAPI
Free · All Tools

Maps & Geolocation Agent Skill

Mapbox/Leaflet integration, geocoding, store locators, marker clusters, and route display.

mapsmapboxleafletgeolocation

The Skill

Full content, every format. Copy it, download it, or install with one command.

SKILL.md
---
description: Mapbox/Leaflet integration, geocoding, store locators, marker clusters, and route display.
homepage: https://yepapi.com/skills/maps-geolocation
metadata:
  tags: [maps, mapbox, leaflet, geolocation]
---

# Maps & Geolocation

## Rules

- Mapbox GL JS for rich interactive maps — `react-map-gl` for React wrapper
- Leaflet as free alternative — `react-leaflet` for React, no API key required for basic tiles
- API key management: `NEXT_PUBLIC_MAPBOX_TOKEN` for client-side Mapbox, never expose server-side secrets
- Geocoding: convert addresses to coordinates — Mapbox Geocoding API or OpenStreetMap Nominatim (free)
- Marker clusters: use `supercluster` or Mapbox built-in clustering for large marker datasets (100+)
- Store locator pattern: geocode user location → query nearby stores with Haversine/PostGIS → display on map
- Route display: Mapbox Directions API for driving/walking routes, render as GeoJSON LineString layer
- Browser geolocation: `navigator.geolocation.getCurrentPosition()` — always handle permission denied gracefully
- Lazy load map component — maps are heavy; use `dynamic(() => import("./Map"), { ssr: false })`

## Patterns

```tsx
// react-map-gl with Mapbox
import Map, { Marker, NavigationControl } from "react-map-gl";
import "mapbox-gl/dist/mapbox-gl.css";

function StoreMap({ stores }: { stores: Store[] }) {
  return (
    <Map
      initialViewState={{ longitude: -122.4, latitude: 37.8, zoom: 11 }}
      mapboxAccessToken={process.env.NEXT_PUBLIC_MAPBOX_TOKEN}
      mapStyle="mapbox://styles/mapbox/streets-v12"
      style={{ width: "100%", height: 400 }}
    >
      <NavigationControl position="top-right" />
      {stores.map((store) => (
        <Marker key={store.id} longitude={store.lng} latitude={store.lat}>
          <Pin />
        </Marker>
      ))}
    </Map>
  );
}
```

```ts
// Haversine distance for nearby search
function haversineDistance(lat1: number, lon1: number, lat2: number, lon2: number): number {
  const R = 6371; // km
  const dLat = ((lat2 - lat1) * Math.PI) / 180;
  const dLon = ((lon2 - lon1) * Math.PI) / 180;
  const a = Math.sin(dLat / 2) ** 2 + Math.cos((lat1 * Math.PI) / 180) * Math.cos((lat2 * Math.PI) / 180) * Math.sin(dLon / 2) ** 2;
  return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
}
```

## Avoid

- Server-side rendering map components — always load with `ssr: false` or `"use client"`
- Rendering 1000+ markers without clustering — kills performance; use supercluster
- Hardcoding coordinates — geocode addresses at build time or on demand
- Ignoring geolocation permission denial — always provide a fallback (manual address entry)

Install

Why Use the Maps & Geolocation Skill?

Without this skill, your AI guesses at maps & geolocation patterns. It might hallucinate deprecated APIs, use outdated conventions, or miss best practices entirely. With it, your AI follows a proven ruleset — every suggestion aligns with current standards.

Drop this skill into your project and your AI instantly knows the rules. Better code suggestions, fewer errors, faster shipping.

Try These Prompts

These prompts work better with the Maps & Geolocation skill installed. Your AI knows the context and writes code that fits.

"Build a store locator with Mapbox, geocoding, and marker clusters"

"Create an interactive map with route display, geolocation, and custom markers"

"Add a location-based search with distance filtering and reverse geocoding"

Maps & Geolocation skill — FAQ

It covers Mapbox and Leaflet integration, geocoding, store locators, and marker clusters. Your AI builds map features with proper loading, error states, and mobile interactions.

Run `npx skills add YepAPI/skills --skill maps-geolocation` in your project root. This copies the skill file into your repo where your AI coding tool can read it automatically.

The skill covers Mapbox for feature-rich maps and Leaflet for lightweight open-source maps. Use Mapbox if you need geocoding, directions, and custom styles. Use Leaflet for simpler use cases.

Want more skills?

Browse all 110 free skills for builders.

See All Skills