> For the complete documentation index, see [llms.txt](https://learn.spexi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.spexi.com/api-reference/code-examples/address-lookup.md).

# Address Lookup

The Spexi Standard Images API uses geographic coordinates (latitude/longitude) for spatial queries rather than street addresses. To work with addresses, you'll need to convert them to coordinates first using a geocoding service.

### Prerequisites

Before running the geocoding example, install the required Python library:

```bash
pip install geopy
```

### Geocoding service

While many geocoding services are available (Google Maps, Mapbox, HERE, etc.), we'll use **Nominatim** - OpenStreetMap's free geocoding service that requires no API key. Nominatim has usage limits (1 request/second) and may be less accurate than commercial services, but it's ideal for demos and moderate usage.

```python
from geopy.geocoders import Nominatim

# Initialize the geocoder
geolocator = Nominatim(user_agent="your_app_name")

# Spexi API configuration
BASE_URL = "https://api-world.spexi.com/api/ogc/v1"
COLLECTION_ID = "your_collection_id"  # Replace with actual collection ID

# Sample addresses to geocode
addresses = [
    "Science World, Vancouver, BC",
    "Palace of Fine Arts, San Francisco, CA", 
    "68 Bluenose Drive, Lunenburg, NS"
]

# Geocode each address
locations = []
for address in addresses:
    location = geolocator.geocode(address)
    if location:
        locations.append({
            "address": address,
            "latitude": location.latitude,
            "longitude": location.longitude
        })
        print(f"✓ {address}")
        print(f"  → {location.latitude:.6f}, {location.longitude:.6f}")
        print(f"  → {BASE_URL}/collections/{COLLECTION_ID}/items?p={location.longitude},{location.latitude},20&focused=focused")
    else:
        print(f"✗ Could not geocode: {address}")
```

### Output

```
✓ Science World, Vancouver, BC
  → 49.273454, -123.103674
  → https://api-world.spexi.com/api/ogc/v1/collections/your_collection_id/items?p=-123.1036739,49.2734536,50&focused=focused
✓ Palace of Fine Arts, San Francisco, CA
  → 37.802919, -122.448403
  → https://api-world.spexi.com/api/ogc/v1/collections/your_collection_id/items?p=-122.4484029,37.8029186,50&focused=focused
✓ 68 Bluenose Drive, Lunenburg, NS
  → 44.376126, -64.312429
  → https://api-world.spexi.com/api/ogc/v1/collections/your_collection_id/items?p=-64.3124287,44.3761265,50&focused=focused
```

The generated URLs can be used directly to query the items endpoint and retrieve aerial imagery for each location:

#### Science World, Vancouver, BC

<figure><img src="/files/yME3aVHhcnyyiVk4235P" alt=""><figcaption></figcaption></figure>

#### Palace of Fine Arts, San Francisco, CA

<figure><img src="/files/OkCeC52boHkThW4X0k7o" alt=""><figcaption></figcaption></figure>

#### 68 Bluenose Drive, Lunenburg, NS

<figure><img src="/files/bkm2DtPYVtMZZljipF21" alt=""><figcaption></figcaption></figure>
