Geocoding API
Utility geocoding endpoint for converting supported city, postal code, city_id, or station inputs to coordinates and metadata.
This API accepts a supported location and returns a latitude, and longitude.
Note: This API returns a lat/lon given a supported city, postal code, or station ID. Most populated cities/postal codes are supported. However, this API is not intended to supplant the need for a dedicated geocoding service or provide address level geocoding. If more precise or robust geocoding is required for your application, we recommend using a dedicated geocoding service.
Request Parameters
| Field | Optional/Required | Type | Data Type | Description |
|---|---|---|---|---|
city
|
Optional | query | string | City lookup value (optionally with state/country). Example: Raleigh,NC |
state
|
Optional | query | string | Optional state or province code used with city lookups. |
country
|
Optional | query | string | Optional 2-letter country code. |
postal_code
|
Optional | query | string | Postal code lookup value. Example: 98104 |
city_id
|
Optional | query | string | Weatherbit city ID. Example: 4487042 |
station
|
Optional | query | string | ICAO or station ID lookup value. |
key
|
Required | query | string | Your registered API key. |
* One of the following location methods is required: city,ST + country, postal_code + country, city_id or station ID .
Example Requests
city
https://api.weatherbit.io/v2.0/geocode?key=API_KEY&city=Raleigh%2CNC&country=US
curl -s "https://api.weatherbit.io/v2.0/geocode?key=API_KEY&city=Raleigh%2CNC&country=US"
require 'uri'
require 'net/http'
require 'json'
uri = URI("https://api.weatherbit.io/v2.0/geocode?key=API_KEY&city=Raleigh%2CNC&country=US")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == "https")
request = Net::HTTP::Get.new(uri)
response = http.request(request)
json = JSON.parse(response.body)
puts JSON.pretty_generate(json)
const https = require("https");
https.get("https://api.weatherbit.io/v2.0/geocode?key=API_KEY&city=Raleigh%2CNC&country=US", (res) => {
let raw = "";
res.on("data", (chunk) => { raw += chunk; });
res.on("end", () => {
const json = JSON.parse(raw);
console.log(JSON.stringify(json, null, 2));
});
}).on("error", (err) => {
console.error(err.message);
});
Example Response HTTP 200
{
"country_code": "US",
"geo_id": "98104-US",
"lat": 47.6036,
"lon": -122.3256,
"name": "King",
"state_code": "WA",
"timezone": "America/Los_Angeles"
}
HTTP Statuses
| Code | Description | Example |
|---|---|---|
| 200 | A geocoding result object. | - |
| 204 | No Data Found | - |
| 400 | Client Error |
|
| 403 | Unauthorized/No Access for current plan level |
|
| 429 | Daily or Velocity limit exceeded See rate limit guidance. |
|
| 500 | Internal Server Error |
|
Return Fields
| Field | Data Type | Description |
|---|---|---|
country_code
|
string | 2-letter country code |
geo_id
|
string | Internal geographic identifier |
lat
|
number | Latitude |
lon
|
number | Longitude |
name
|
string | Resolved city, county, or postal area name |
state_code
|
string | State or province abbreviation when available |
timezone
|
string | Local IANA time zone |
Returns latitude and longitude for supported city, postal code, station, or city_id inputs. Use this utility endpoint to normalize locations before calling Weatherbit APIs.