You are here

public function GeoHash::read in geoPHP 8

Same name and namespace in other branches
  1. 7 geoPHP/lib/adapters/GeoHash.class.php \GeoHash::read()

Convert the geohash to a Point. The point is 2-dimensional.

Parameters

string $hash a geohash:

Return value

Point the converted geohash

Overrides GeoAdapter::read

See also

GeoAdapter::read()

File

geoPHP/lib/adapters/GeoHash.class.php, line 18

Class

GeoHash
PHP Geometry GeoHash encoder/decoder.

Code

public function read($hash, $as_grid = FALSE) {
  $ll = $this
    ->decode($hash);
  if (!$as_grid) {
    return new Point($ll['medlon'], $ll['medlat']);
  }
  else {
    return new Polygon(array(
      new LineString(array(
        new Point($ll['minlon'], $ll['maxlat']),
        new Point($ll['maxlon'], $ll['maxlat']),
        new Point($ll['maxlon'], $ll['minlat']),
        new Point($ll['minlon'], $ll['minlat']),
        new Point($ll['minlon'], $ll['maxlat']),
      )),
    ));
  }
}