Geographies
Description
Use this endpoint to retrieve the names and IDs of geographies (e.g. neighbourhoods, cities) associated with a specific location (lat
/lng
). Geographies are maintained by Local Logic's Data Team and represent a named geographical polygon used to refer to an area. These polygons are also used to compute various Local Logic insights for the various types of polygons represented in our geographies: neighborhoods, cities, zip codes, and metro areas.
The geography IDs (e.g. g10_f25dyhcn
) in the returned dictionary are used to query the Local Profiles, Location Scores, Demographics, Market Statics, Value Drivers, and Similar Neighborhoods APIs to return those data products by geog_id
.
Geography Levels
Local Logic geographies exist with a hierarchy that allows multiple geographies to exist around a single location, with the ability to distinguish different types of geographies based on the geography level. Here's a summary of the possible geography levels, which can also be obtained by looking at the two-digit geography level following g
in any given geography ID.
Geography Level | Definition | Example | Availability |
---|---|---|---|
10 | Neighborhood | Greenwich Village, NYC g10_dr5rsp2g | US & CA |
20 | Macro-neighborhood Borough / Arrondissement | Manhattan, NYC g20_dr5ruz6b | US & CA |
30 | City Municipality | New York, NY g30_dr5rm6xu | US & CA |
32 | Zip Code | Zip Code 10014 g32_dr5rezqm | US only |
35 | Census County Division | Manhattan g35_dr5ruy8t | US only |
40 | Metro Area | New York-Newark-Jersey City, NY-NJ-PA g40_dr5ryyd3 | US & CA |
60 | State / Province | New York state g60_drdhpv86 | US & CA |
70 | Country | United States g70_c2pt4mux | US & CA |
GET v3/geographies
GET v3/geographies
Header
This API uses JWT token based authentication. This JWT Bearer token is what is used to populate the
Authorization
header below.
Instructions on how to retrieve this token can be found at Getting Started.
Header | Status | Description |
---|---|---|
Authorization | required | Your bearer token retrieved from our authorization API, ex. Bearer eyJhbGci... |
Accept | required | The datatype to request, this API will return application/json . |
QueryString
Query by Latitude and Longitude
Parameter | Status | Description |
---|---|---|
lat | required | A decimal number between -90 and 90 (Latitude) |
lng | required | A decimal number between -180 and 180 (Longitude) |
include | optional | The only supported value is "geometry". If set, the response will contain the geometry of each of the geographies. Geometries are returned as a list of lists of tuples of lat/lng. This feature only works for Canadian geographies. |
When querying by latitude and longitude, the ordered results are by geography level, from smallest to largest.
Query by Name
Parameter | Status | Description |
---|---|---|
name | required | The name of the geography to search for. |
language | optional | The language in which the name is provided. Accepted Values: en , fr .Default: en . |
location_codes | optional | A comma-separated list of location codes to filter the results. If left empty then all locations are included. The codes are composed of <2 capitalized chars country code>_<2 capitalized chars state/province code> . Example values: CA_QC for Canada, Quebec. US_NY for United-States, New York. |
levels | optional | A comma-separated list of levels to filter the results. If left empty then all levels are included. Accepted Values: 10 , 20 , 30 , 32 , 35 . |
limit | optional | How many items to return, at most. Maximum: 50 Default: 5 |
include | optional | The only supported value is "geometry". If set, the response will contain the geometry of each of the geographies. Geometries are returned as a list of lists of tuples of lat/lng. This feature only works for Canadian geographies. |
When querying by name, the ordered results are by similarity of the geography name to the searched text, from most similar to least similar.
Usage examples
- NodeJS
require('node-fetch')('https://api.locallogic.co/v3/geographies?' + new URLSearchParams({
lat: 41.847206,
lng: -87.668825,
}), {
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: 'Bearer eyJhbGciOiJ...'
}
})
.then(response => response.json())
.then(body => {
console.log(body)
})
.catch(error => {
console.log(error)
})
Response example
{
"data": {
"type": "geographies",
"geographies": {
"g10_f25dyhcn": {
"name": {
"fr": "Le Faubourg Saint-Laurent",
"en": "Le Faubourg Saint-Laurent"
},
"level_type": {
"fr": "quartier",
"en": "neighbourhood"
},
"level": 10
},
"g20_f25dyhf3": {
"name": {
"en": "Ville-Marie",
"fr": "Ville-Marie"
},
"level_type": {
"en": "borough",
"fr": "arrondissement"
},
"level": 20
},
"g30_f25dfkes": {
"name": {
"en": "Montréal",
"fr": "Montréal"
},
"level_type": {
"en": "city",
"fr": "ville"
},
"level": 30
}
}
},
"meta": {
"order": [
"g10_f25dyhcn",
"g20_f25dyhf3",
"g30_f25dfkes"
]
}
}
GET v3/geographies/{geog_id}
GET v3/geographies/{geog_id}
Header
This API uses JWT token based authentication. This JWT Bearer token is what is used to populate the
Authorization
header below.
Instructions on how to retrieve this token can be found at Getting Started.
Header | Status | Description |
---|---|---|
Authorization | required | Your bearer token retrieved from our authorization API, ex. Bearer eyJhbGci... |
Accept | required | The datatype to request, this API will return application/json . |
QueryString
Parameter | Status | Description |
---|---|---|
include | optional | The only supported value is "geometry". If set, the response will contain the geometry of each of the geographies. Geometries are returned as a list of lists of tuples of lat/lng. This feature only works for Canadian geographies. |
Usage examples
- NodeJS
require('node-fetch')('https://api.locallogic.co/v3/geographies/g10_c3r13ej7'), {
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: 'Bearer eyJhbGciOiJ...'
}
})
.then(response => response.json())
.then(body => {
console.log(body)
})
.catch(error => {
console.log(error)
})
Response example
{
"data": {
"type": "geographies",
"geographies": {
"g35_dnuqnr1n": {
"name": {
"fr": "Whiteoak",
"en": "Whiteoak"
},
"level_type": {
"fr": "canton",
"en": "township"
},
"level": 35
}
}
},
"meta": {
"order": [
"g35_dnuqnr1n"
]
}
}
Error codes
When calling Local Logic’s API, you may receive an HTTP error code. These errors are explained below. In general, error codes starting with “4” are due to an invalid API call and can be fixed on your end, whereas error codes starting with “5” are due to server errors (that is, problems on our end). If you receive something not described here, please contact us at support@locallogic.co.
400 - BadRequest
This error code happens when the request inputs are incorrect. Use the detail field of the response for clarification. Example:
{
"code": "LocalLogic.API.BadRequest",
"detail": "ValidationErrors: AroundEndpoint is invalid:\n\tinclude is invalid: \"bad_input\" is not an acceptable value: \"groceries\", \"restaurants\", \"nightlife\", \"cafes\", \"shopping\", \"daycares\", \"primary_schools\", \"high_schools\""
}
401 - Unauthorized
This error code happens when your API key cannot access specific resources or locations. For example, some API keys can only access certain countries / states / provinces. Feel free to contact us for more information. Example:
{
"code": "LocalLogic.API.Unauthorized",
"detail": "Your API KEY doesn't support this region"
}
403 - Forbidden
This error code happens when you forgot to include security credentials with your request or you are requesting a parameter that you do not have access to. Example:
{
"message": "Forbidden"
}
404 - NotFound
This error code happens when we don’t have data for the requested location. For example, if you send a lat/lng pair for a location in Antarctica, we will return this error as we don’t have data for Antarctica (yet!). Example:
{
"code": "LocalLogic.API.NotFound",
"detail": "No Location Scores found for this location."
}
422 - Unprocessable Entity
This error code is returned when the correct parameters have been sent however, the data they contain is not valid. For example, if you send a lat/lng pair and the latitude is invalid (ie. not in the range [-90, 90]) and/or the longitude is invalid (ie. not in the range [-180, 180]).
{
"message": "Latitude must be within [-90, 90], Longitude must be within [-180, 180], Requires at least lat/lng pair, or geography_ids. None supplied.",
"code": "LocalLogic.API.BadRequest",
"statusCode": 422
}
500 - ServerError
This error code means that an error occurred on our end. Feel free to retry the same request to see if the problem persists. If you received a lot of these errors, please contact us at support@locallogic.co Example:
{
"code": "LocalLogic.API.ServerError",
"detail": "No Location Scores found for this location."
}
502 - BadGateway
This error code means that an error came from our cloud provider. Feel free to retry the same request to see if the problem persists. Example:
{
"message": "Internal server error"
}