---
title: Geo
summary: The geographic data associated with a particular IP address.
url: https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/geo/class.Geo/
---

**Kind:** Class  
**Module:** [geo](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/geo/)  
**Package:** compute-sdk-cpp 0.7.0  
**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L81

Include `fastly/geo.h` to use this class.

The geographic data associated with a particular IP address.

## Methods

### area_code

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L99

```cpp
uint16_t fastly::geo::Geo::area_code()
```

The telephone area code associated with an IP address.

These are only available for IP addresses in the United States, its territories, and Canada.

**Returns**

`uint16_t`

### as_name

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L88

```cpp
std::string fastly::geo::Geo::as_name()
```

The name of the organization associated with `as_number`.

For example, `fastly` is the value given for IP addresses under AS-54113.

**Returns**

`std::string`

### as_number

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L93

```cpp
uint32_t fastly::geo::Geo::as_number()
```

[Autonomous system](https://en.wikipedia.org/wiki/Autonomous_system_(Internet)) (AS) number.

**Returns**

`uint32_t`

### city

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L102

```cpp
std::string fastly::geo::Geo::city()
```

City or town name.

**Returns**

`std::string`

### conn_speed

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L105

```cpp
ConnSpeed fastly::geo::Geo::conn_speed()
```

Connection speed.

**Returns**

`ConnSpeed`

### conn_type

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L108

```cpp
ConnType fastly::geo::Geo::conn_type()
```

Connection type.

**Returns**

`ConnType`

### continent

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L111

```cpp
Continent fastly::geo::Geo::continent()
```

Continent.

**Returns**

`Continent`

### country_code

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L124

```cpp
std::string fastly::geo::Geo::country_code()
```

A two-character [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country code for the country associated with an IP address.

The US country code is returned for IP addresses associated with overseas United States military bases.

These values include subdivisions that are assigned their own country codes in ISO 3166-1. For example, subdivisions NO-21 and NO-22 are presented with the country code SJ for Svalbard and the Jan Mayen Islands.

**Returns**

`std::string`

### country_code3

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L133

```cpp
std::string fastly::geo::Geo::country_code3()
```

A three-character [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) country code for the country associated with the IP address.

The USA country code is returned for IP addresses associated with overseas United States military bases.

**Returns**

`std::string`

### country_name

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L140

```cpp
std::string fastly::geo::Geo::country_name()
```

Country name.

This field is the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) English short name for a country.

**Returns**

`std::string`

### latitude

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L148

```cpp
double fastly::geo::Geo::latitude()
```

Latitude, in units of degrees from the equator.

Values range from -90.0 to +90.0 inclusive, and are based on the [WGS 84](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinate reference system.

**Returns**

`double`

### longitude

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L157

```cpp
double fastly::geo::Geo::longitude()
```

Longitude, in units of degrees from the [IERS Reference Meridian](https://en.wikipedia.org/wiki/IERS_Reference_Meridian).

Values range from -180.0 to +180.0 inclusive, and are based on the [WGS 84](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinate reference system.

**Returns**

`double`

### metro_code

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L161

```cpp
int64_t fastly::geo::Geo::metro_code()
```

Metro code, representing designated market areas (DMAs) in the United States.

**Returns**

`int64_t`

### postal_code

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L172

```cpp
std::string fastly::geo::Geo::postal_code()
```

The postal code associated with the IP address.

These are available for some IP addresses in Australia, Canada, France, Germany, Italy, Spain, Switzerland, the United Kingdom, and the United States.

For Canadian postal codes, this is the first 3 characters. For the United Kingdom, this is the first 2-4 characters (outward code). For countries with alphanumeric postal codes, this field is a lowercase transliteration.

**Returns**

`std::string`

### proxy_description

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L175

```cpp
ProxyDescription fastly::geo::Geo::proxy_description()
```

Client proxy description.

**Returns**

`ProxyDescription`

### proxy_type

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L178

```cpp
ProxyType fastly::geo::Geo::proxy_type()
```

Client proxy type.

**Returns**

`ProxyType`

### region

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L220

```cpp
std::optional<std::string> fastly::geo::Geo::region()
```

[ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) country subdivision code.

For countries with multiple levels of subdivision (for example, nations within the United Kingdom), this variable gives the more specific subdivision.

This field can be `std::nullopt` for countries that do not have ISO country subdivision codes. For example, `std::nullopt` is given for IP addresses assigned to the Åland Islands (country code AX, illustrated below).

###### Examples

Region values are the subdivision part only. For typical use, a subdivision is normally formatted with its associated country code. The following example illustrates constructing an [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) two-part country and subdivision code from the respective fields:

code   
Region Name   
Country   
ISO 3166-2 subdivision    

AX   
Ödkarby   
Åland Islands   
(none)    

DE-BE   
Berlin   
Germany   
Land (State)    

GB-BNH   
Brighton and Hove   
United Kingdom   
Unitary authority    

JP-13   
東京都 (Tōkyō-to)   
Japan   
Prefecture    

RU-MOW   
Москва́ (Moscow)   
Russian Federation   
Federal city    

SE-AB   
Stockholms län   
Sweden   
Län (County)    

US-CA   
California   
United States   
State

**Returns**

`std::optional<std::string>`

```cpp
auto
client_ip{fastly::Request::from_client().get_client_ip_addr().value()};
auto geo{fastly::geo::geo_lookup(client_ip).value()};
if (auto region = geo.region()) {
  return std::format("{}-{}", geo.country_code(), region.value());
} else {
  return geo.country_code();
}
```

### utc_offset

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/geo.h#L226

```cpp
std::optional<UtcOffset> fastly::geo::Geo::utc_offset()
```

Time zone offset from coordinated universal time (UTC) for `city`.

Returns `std::nullopt` if the geolocation database does not have a time zone offset for this IP address.

**Returns**

`std::optional<UtcOffset>`
