Index: trunk/extensions/Maps/Maps_CoordinateParser.php |
— | — | @@ -199,22 +199,32 @@ |
200 | 200 | */ |
201 | 201 | private static function formatCoordinate( $coordinate, $targetFormat ) { |
202 | 202 | $coordinate = (float)$coordinate; |
| 203 | + |
203 | 204 | switch ( $targetFormat ) { |
204 | 205 | case Maps_COORDS_FLOAT: |
205 | 206 | return $coordinate; |
206 | 207 | case Maps_COORDS_DMS: |
207 | 208 | $isNegative = $coordinate < 0; |
| 209 | + $coordinate = abs( $coordinate ); |
208 | 210 | |
209 | | - $degrees = $isNegative ? ceil( $coordinate ) : floor( $coordinate ); |
| 211 | + $degrees = floor( $coordinate ); |
210 | 212 | $minutes = ( $coordinate - $degrees ) * 60; |
211 | | - $seconds = ( $minutes - ( $isNegative ? ceil( $minutes ) : floor( $minutes ) ) ) * 60; |
| 213 | + $seconds = ( $minutes - floor( $minutes ) ) * 60; |
212 | 214 | |
213 | | - return $degrees . Maps_GEO_DEG . ' ' . ( $isNegative ? ceil( $minutes ) : floor( $minutes ) ) . Maps_GEO_MIN . ' ' . round( $seconds ) . Maps_GEO_SEC; |
| 215 | + $result = $degrees . Maps_GEO_DEG . ' ' . floor( $minutes ) . Maps_GEO_MIN . ' ' . round( $seconds ) . Maps_GEO_SEC; |
| 216 | + if ( $isNegative ) $result = '-' . $result; |
| 217 | + |
| 218 | + return $result; |
214 | 219 | case Maps_COORDS_DD: |
215 | 220 | return $coordinate . Maps_GEO_DEG; |
216 | 221 | case Maps_COORDS_DM: |
217 | 222 | $isNegative = $coordinate < 0; |
218 | | - return round( $coordinate ) . Maps_GEO_DEG . ' ' . ( $coordinate - ( $isNegative ? ceil( $coordinate ) : floor( $coordinate ) ) ) * 60 . Maps_GEO_MIN; |
| 223 | + $coordinate = abs( $coordinate ); |
| 224 | + |
| 225 | + $result = round( $coordinate ) . Maps_GEO_DEG . ' ' . ( $coordinate - floor( $coordinate ) ) * 60 . Maps_GEO_MIN; |
| 226 | + if ( $isNegative ) $result = '-' . $result; |
| 227 | + |
| 228 | + return $result; |
219 | 229 | default: |
220 | 230 | throw new Exception( __METHOD__ . " does not support formatting of coordinates to the $targetFormat notation." ); |
221 | 231 | } |