# Map search
A map with pins, and a list of cards beside it, both following the same filters. This guide
builds it with two calls: [`GET /v1/listings/map`](../reference/endpoints/map-listings.md)
for the map and [`GET /v1/listings`](../reference/endpoints/search-listings.md)
for the list.
## The two calls
Both take the same filters. For the area on screen, send the map's corners as `location.bbox`:
```
GET /v1/listings/map?location.bbox=-75.42,40.00,-75.30,40.08&status=active&price.max=600000
GET /v1/listings?location.bbox=-75.42,40.00,-75.30,40.08&status=active&price.max=600000&limit=24
```
`location.bbox` is `minLng,minLat,maxLng,maxLat`: west, south, east, north.
The map call answers with pins, or with clusters when the area holds more than 500 listings:
```json
{ "data": { "total": 3, "pins": [ { "listingKey": "805454359664", "lat": 40.01, "lng": -75.3, "price": 400000, "status": "active" } ], "clusters": [] } }
```
```json
{ "data": { "total": 600, "pins": [], "clusters": [ { "lat": 40.4, "lng": -75.8, "count": 37, "bbox": [-75.81, 40.39, -75.79, 40.41] } ], "gridCellDegrees": 0.022 } }
```
- **A pin** has the key, the point, the list price (null when the price may not be shown) and
the status. For anything more, such as a card when the visitor clicks, fetch
`GET /v1/listings/{listingKey}`.
- **A cluster** has its center, how many listings it stands for, and the box that holds them.
When the visitor clicks one, zoom the map to its `bbox`: a smaller area turns clusters into
pins.
The list call answers with listing objects, 24 a page, with `meta.page.total` and a
`nextCursor` for the next page.
## In the browser, with the publishable key
A map moves in the browser, so call from the browser with your **publishable** key (`pk_…`).
It is made to be seen in a page: it works only from the website addresses on your account
(and from `localhost`, for a test key), and by itself it can only read. Your secret key
(`sk_…`) never goes into a page ([authentication](../concepts/authentication.md)).
```html
```
`showCards`, `showDisclosures` and `showUnavailable` are yours. A card shows at least the
listing office's name, photos use `object-fit: contain`, and the page shows the `compliance`
texts ([compliance](compliance.md)).
### Keep the calls few
A publishable key's requests share [limits](../concepts/rate-limits.md) per key and per visitor
address: 20 a second, with bursts of 50. A map can use that up quickly if every small movement
calls the API.
- **Wait until the map rests** (the 250 ms above), and **abort the call you no longer need.**
- On `429 rate_limited`, wait `Retry-After` seconds and try once more. A script can read the
header.
- Don't fetch a detail for every pin. Fetch one when the visitor asks for it.
## Searching a town, a ZIP code or a county
Let the visitor type a name ([autocomplete](autocomplete.md)), then search the place by its ID
and move the map to it:
```
GET /v1/places/pl_… → "bbox": [-75.35, 39.98, -75.25, 40.06]
GET /v1/listings/map?location.placeIds=pl_…
GET /v1/listings?location.placeIds=pl_…&limit=24
```
Filters combine with AND, so `location.placeIds` together with `location.bbox` finds the
place's listings inside the area on screen.
## Listings that are never on the map
A listing whose address is hidden has no point, so it is never a pin, never in a cluster and
never found by `location.bbox`, a radius or a drawn shape
([hidden addresses](../concepts/hidden-addresses.md)). It **is** found by a place, a city or a
ZIP code. So for a search by place, the list can hold listings the map does not, and its
`total` can be larger than the map's. Show those cards with their `addressNotice` in place of
an address, and no "show on map" link.
## Premium: outlines and drawn shapes
- **A place's outline:** [`GET /v1/places/{placeId}/geometry?zoom=`](../reference/endpoints/get-place-geometry.md)
with the map's zoom returns a GeoJSON outline simplified for that zoom. Draw it once for a
place and zoom; it has [limits of its own](../concepts/rate-limits.md#place-outlines).
- **A shape the visitor draws:** send it as `location.shape` in the body of
`POST /v1/listings/map` and `POST /v1/listings/search` ([drawn shapes](../concepts/shapes.md)).
A drawn shape exists in the `POST` forms only.
- **A shape the visitor keeps:** [save it](../reference/saved-shapes.md) and send its
`location.shapeId`, which also works in the `GET` forms and in a saved search.
A key on a Basic account gets [`403 tier_insufficient`](../errors/tier_insufficient.md) for
these. Searching a place by its ID works on every tier.
## Sorting by distance
`sort=distance` on the list needs a center: send `location.radius.center=lng,lat` and
`location.radius.meters`. Like every spatial filter, it finds only listings with a shown
address.
## Map tiles
The example loads its map pictures from OpenStreetMap's own tile servers, which are free and
meant **for light use only**. They are fine for building and for a demo. A site with real
traffic needs a tile provider of its own (many offer OpenStreetMap-based tiles): change the
tile address and its credit line, and nothing else.
## On your server instead
The same two calls work from your server with the secret key, which is how a page is built
for visitors without scripts and for search engines ([an SEO-friendly site](seo.md)). Many
sites do both: the first view built on the server, and the moving map in the browser.