Prompt
How do I turn addresses into coordinates with an API?
Latest observation
Oct 15, 2026
OpenAI APIWeb search: off
To turn an address into coordinates, you use a geocoding API.
Basic idea
You send an address like:
1600 Amphitheatre Parkway, Mountain View, CA
and the API returns:
- latitude:
37.422 - longitude:
-122.084
Common workflow
- Pick a geocoding service
- Send the address in a request
- Parse the JSON response
- Extract
latandlng
Example using Google Geocoding API
Request:
GET https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY
Example response:
{
"results": [
{
"geometry": {
"location": {
"lat": 37.422,
"lng": -122.084
}
}
}
],
"status": "OK"
}
Example in Python
import requests
address = "1600 Amphitheatre Parkway, Mountain View, CA"
url = "https://maps.googleapis.com/maps/api/geocode/json"
params = {
"address": address,
"key": "YOUR_API_KEY"
}
response = requests.get(url, params=params)
data = response.json()
location = data["results"][0]["geometry"]["location"]
print(location["lat"], location["lng"])
Other popular geocoding APIs
- Google Maps Geocoding API
- Mapbox Geocoding API
- OpenCage
- Nominatim (OpenStreetMap-based; has usage limits/policies)
Things to watch for
- API key required for most services
- Rate limits
- Ambiguous addresses may return multiple results
- Some APIs return confidence/precision info
- Always check the API’s usage policy
If you want, I can show you:
- a JavaScript example
- a Python example
- or how to do this with a free/open-source geocoding API