dblLongitude = (double)$dblLon; $this->dblLatitude = (double)$dblLat; } /** * Output the point as string (lon,lat) * * Some strange people (like Google) display coordinates like y,x instead of * the logical x,y-way (see cartesian coordinate system). If you prefer the * first way, feel free to switch both... * * @return string */ public function __toString() { return "({$this->dblLongitude},{$this->dblLatitude})"; } /** * Returns the latitude of the geo coord * * @return double */ public function getLatitude() { return $this->dblLatitude; } /** * Returns the longitude of the geo coord * * @return double */ public function getLongitude() { return $this->dblLongitude; } /** * Transforms the EXIF geo cood array into a decimal format * * Array * ( * [0] => 52/1 * [1] => 3367/100 * [2] => 0/1 * ) * * to 52.561167 * * @param string $reference N, E, W or S * @param array $coordinate Coordinate */ protected static function exifGeoCoordinateToDecimal($reference, array $coordinate) { list($a,$b) = explode("/", $coordinate[0]); list($c,$d) = explode("/", $coordinate[1]); list($e,$f) = explode("/", $coordinate[2]); $prefix = $reference == 'S' || $reference == 'W' ? -1 : 1; $a = $b > 0 ? $a / $b : $a; $c = $d > 0 ? $c / $d : $c; $e = $f > 0 ? $e / $f : $e; return $prefix * round(($a + ($c * 60 + $e) / 3600), 6); } /** * Reads an image file and returns the extracted geo information * * Reads an image file, transforms the exif geo information into a reusable * geo point object * * @param string $strFilename File name * @return GeoPoint * @throws UnexpectedValueException, Exception */ public static function constructFromImageFile($strFilename) { if (file_exists($strFilename)) { $arrInfos = exif_read_data($strFilename, "EXIF"); if (is_array($arrInfos["GPSLatitude"]) && is_array($arrInfos["GPSLongitude"])) { $dblLat = self::exifGeoCoordinateToDecimal($arrInfos["GPSLatitudeRef"], $arrInfos["GPSLatitude"]); $dblLon = self::exifGeoCoordinateToDecimal($arrInfos["GPSLongitudeRef"], $arrInfos["GPSLongitude"]); return new self($dblLon, $dblLat); } else throw new UnexpectedValueException("Exchangeable image information (EXIF) without GPS data"); } else throw new Exception("File not found"); } } echo GeoPoint::constructFromImageFile("img_0013.jpg"); ?>