declare local var.chunk_size FLOAT;
declare local var.lat FLOAT;
declare local var.long FLOAT;
declare local var.gridID STRING;

# Grid square size is in decimal degrees.  0.1 degrees produces a
# square of approximately 11km across (123 square kilometers), or
# about 12 million unique locations on the Earth's surface
# (albeit most of them will be ocean)
set var.chunk_size = 0.1;

if (var.chunk_size > 0) {
  set var.lat = client.geo.latitude;
  set var.long = client.geo.longitude;

  set var.lat /= var.chunk_size;
  set var.lat = math.floor(var.lat);
  set var.lat *= var.chunk_size;
  set var.lat += var.chunk_size;

  set var.long /= var.chunk_size;
  set var.long = math.floor(var.long);
  set var.long *= var.chunk_size;

  set var.gridID = var.lat + "," + var.long;

  log "Grid ID: " + var.gridID + ". Nearest city: " + client.geo.city;

  set req.http.geo-grid-id = var.gridID;
}