LocationData
Inspect the geolocation data of the incoming request.
You must either deploy your app to Cloudflare Workers or use Cloudflare as a proxy to use the LocationData
API.
Setup
import { LocationData } from 'https://deno.land/x/cheetah/mod.ts'
app.get('/', (c) => {
const location = new LocationData(c)
})
Get the City
The city the request originated from.
e.g. Austin
location.city
Get the Region
If known, the ISO 3166-2 name for the first level region associated with the IP address of the incoming request.
e.g. Texas
location.region
Get the Country
The ISO 3166-1 Alpha 2 country code the request originated from.
If you're using CLoudflare Workers and your worker is configured to accept TOR connections, this may also be T1
, indicating a request that originated over TOR.
If Cloudflare is unable to determine where the request originated this property is omitted.
e.g. GB
location.country
Get the Continent
A two-letter code indicating the continent the request originated from.
e.g. NA
location.continent
Get the Region Code
If known, the ISO 3166-2 code for the first-level region associated with the IP address of the incoming request.
e.g. TX
location.regionCode
Get the Latitude
Latitude of the incoming request.
e.g. 30.27130
location.latitude
Get the Longitude
Longitude of the incoming request.
e.g. -97.74260
location.longitude
Get the Postal Code
Postal code of the incoming request.
e.g. 78701
location.postalCode
Get the Timezone
Timezone of the incoming request.
e.g. America/Chicago
location.timezone
Get the Datacenter
The three-letter IATA airport code of the data center that the request hit.
e.g. DFW
location.datacenter