diff -urp original_geo/geo.module geo/geo.module --- original_geo/geo.module 2010-01-18 20:47:01.000000000 +0100 +++ geo/geo.module 2010-04-23 22:49:47.000000000 +0200 @@ -155,6 +155,12 @@ function geo_field_formatter_info() { 'gis types' => array('point'), 'gis input' => 'array', ), + 'latlon' => array( + 'label' => t('Latitude / Longitude'), + 'field types' => geo_field_type_names(), + 'gis types' => array('point'), + 'gis input' => 'array', + ), 'georss' => array( 'label' => t('GeoRSS'), 'field types' => geo_field_type_names(), diff -urp original_geo/theme/geo.theme.inc geo/theme/geo.theme.inc --- original_geo/theme/geo.theme.inc 2009-12-10 14:25:34.000000000 +0100 +++ geo/theme/geo.theme.inc 2010-04-23 23:41:59.000000000 +0200 @@ -22,6 +22,12 @@ function geo_theme_theme() { 'path' => $path, 'gis input' => 'array', ), + 'geo_formatter_latlon' => array( + 'arguments' => array('element' => NULL), + 'file' => 'geo.theme.inc', + 'path' => $path, + 'gis input' => 'array', + ), 'geo_formatter_georss' => array( 'arguments' => array('element' => NULL), 'file' => 'geo.theme.inc', @@ -61,6 +67,20 @@ function theme_geo_formatter_lon($elemen if ($element['#item']['array']) return $element['#item']['array']['lon']; } +function theme_geo_formatter_latlon($element) { + if ($element['#item']['array']) { + $output = '
'; + $output .= ''; + $lat = geo_dec_to_dms($element['#item']['array']['lat']); + $output .= $lat['deg'] . '° ' . $lat['min'] . '′ ' . $lat['sec'] . '″ ' . 'N'; + $output .= ' '; + $lon = geo_dec_to_dms($element['#item']['array']['lon']); + $output .= $lon['deg'] . '° ' . $lon['min'] . '′ ' . $lon['sec'] . '″ ' . 'W'; + $output .= '
'; + return $output; + } +} + function theme_geo_formatter_georss($element) { $item = $element['#item']; @@ -85,3 +105,23 @@ function theme_geo_latlon($element) { $output = '
'. $element['#children'] .'
'; return theme('form_element', $element, $output); } + + +/* + Converts decimal longitude / latitude to DMS + ( Degrees / minutes / seconds ) + This is the piece of code which may appear to + be inefficient, but to avoid issues with floating + point math we extract the integer part and the float + part by using a string function. +*/ + +function geo_dec_to_dms($dec) { + $vars = explode(".",$dec); + $deg = $vars[0]; + $tempma = "0.".$vars[1]; + $tempma = $tempma * 3600; + $min = floor($tempma / 60); + $sec = $tempma - ($min*60); + return array("deg"=>$deg,"min"=>$min,"sec"=>$sec); +} \ No newline at end of file