source: extensions/rv_gmaps/trunk/include/functions_metadata.php

Last change on this file was 22180, checked in by rvelices, 11 years ago

rv_gmaps: more forgiving about some wrong exif gps formatting + small technical stuff

File size: 1.0 KB
Line 
1<?php
2function parse_fract( $f )
3{
4        $nd = explode( '/', $f );
5        return $nd[0] ? ($nd[0]/$nd[1]) : 0;
6}
7
8function parse_lat_lon( $arr )
9{
10        $v=0;
11        $v += parse_fract( $arr[0] );
12        $v += parse_fract( $arr[1] )/60;
13        $v += parse_fract( $arr[2] )/3600;
14        return $v;
15}
16
17function exif_to_lat_lon( $exif )
18{
19        $exif = array_intersect_key( $exif, array_flip( array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude') ) );
20        if ( count($exif)!=4 )
21                return '';
22        if ( !in_array($exif['GPSLatitudeRef'], array('S', 'N') ) )
23                return 'GPSLatitudeRef not S or N';
24        if ( !in_array($exif['GPSLongitudeRef'], array('W', 'E') ) )
25                return 'GPSLongitudeRef not W or E';
26        if (!is_array($exif['GPSLatitude']) or !is_array($exif['GPSLongitude']) )
27                return 'GPSLatitude and GPSLongitude are not arrays';
28               
29        $lat = parse_lat_lon( $exif['GPSLatitude'] );
30        if ( $exif['GPSLatitudeRef']=='S' )
31                $lat = -$lat;
32        $lon = parse_lat_lon( $exif['GPSLongitude'] );
33        if ( $exif['GPSLongitudeRef']=='W' )
34                $lon = -$lon;
35        return array ($lat,$lon);
36}
37
38?>
Note: See TracBrowser for help on using the repository browser.