client.geo.latitude

FLOAT, read-only.

Available in all subroutines.

Latitude, in units of degrees from the equator. Values range from -90 to +90 inclusive, with the exception of the special value 999.9 used to indicate absent data.

The latitude given is based on the WGS 84 coordinate reference system.

Example

An example showing construction of a geo URI as specified by RFC 5870 in VCL:

declare local var.geouri STRING;
set var.geouri = "geo:" + client.geo.latitude + "," + client.geo.longitude;

This produces a URI of the form geo:37.786971,-122.399677 (where WGS 84 is the default CRS).

Example

Here's an example showing classification to the five main Geographical zones in VCL (latitude values as of Oct 2018):

sub client_geo_zone STRING {
declare local var.zone STRING;
if (client.geo.latitude == 999.9) {
set var.zone = "";
} else if (client.geo.latitude >= 66.5) { # Arctic circle
set var.zone = "North frigid";
} else if (client.geo.latitude >= 23.5) { # Topic of Cancer
set var.zone = "North temperate";
} else if (client.geo.latitude <= -66.5) { # Antarctic Circle
set var.zone = "South frigid";
} else if (client.geo.latitude <= -23.5) { # Tropic of Capricorn
set var.zone = "South temperate";
} else {
set var.zone = "Torrid";
}
return var.zone;
}

You can use VCL to convert to degrees, minutes and seconds:

Converting to Degrees, Minutes and Seconds is a little long-winded, but possible in VCL:

declare local var.deg INTEGER;
declare local var.min INTEGER;
declare local var.sec FLOAT;
declare local var.angle FLOAT;
declare local var.whole FLOAT;
declare local var.frac FLOAT;
set var.angle = client.geo.latitude; # input
if (var.angle < 0.0) {
set var.angle *= -1;
}
set var.frac = var.angle;
set var.whole = var.frac;
set var.frac %= 1.0;
set var.whole -= var.frac;
set var.deg = var.whole; # truncated, integer by rounding
set var.frac *= 60.0;
set var.whole = var.frac;
set var.frac %= 1.0;
set var.whole -= var.frac;
set var.min = var.whole; # truncated, integer by rounding
set var.sec = var.frac;
set var.sec *= 60.0; # floating seconds
log client.geo.latitude + " = " + var.deg "° " var.min "′ " var.sec "″ "
+ if (client.geo.latitude < 0.0, "S", "N");

For example, a latitude of 59.926 produces 59° 55′ 33.600″ N. The and symbols are Unicode prime symbols, not quotes.

Try it out

client.geo.latitude is used in the following solution recipes, which show real world use cases. Click RUN to provision a Fastly service, execute the code on Fastly, and see how the function behaves.

Decorating origin requests with GeoIP

Add GeoIP data about the client browser as extra headers in any requests from Fastly to your origin.

Geofencing / geoblocking content by region

Group countries to cache content by custom regions or reject requests from some regions entirely.

User contributed notes

We welcome comments that add use cases, ideas, tips, and caveats. All comments will be moderated before publication. To post support questions, visit our support center and we'll find you the help you need.