sexagesimalToDecimal(latitude, latitudeRef, longitude, longitudeRef)
Last updated December 20, 2012
Version: 1 | Requires: CF9 | Library: UtilityLib
Description:
Say you have a .jpg file and it has EXIF data with its location information. Sometimes the EXIF location information is in sexagesimal format which is hard to use in popular mapping libraries. This code puts the information into the more "normal" decimal lat/lng format. Ben Nadel was the inspiration for this, see: http://www.bennadel.com/index.cfm?event=blog.viewcode&id=1832&index=1
Return Values:
A struct with keys longitude and latitude
Example:
<cfimage action="read" source="c:\foo.jpg" name="img">
<cfset exifTags = ImageGetEXIFMetaData(img)>
<cfset coordinates = sexagesimalToDecimal(
exifTags["GPS Latitude"],
exifTags["GPS Latitude Ref"],
exifTags["GPS Longitude"],
exifTags[ "GPS Longitude Ref" ]
)>
<cfdump var="#coordinates#">
Parameters:
Name | Description | Required |
---|---|---|
latitude | Latitude in degrees/min/sec, using " and ' delimiters | Yes |
latitudeRef | N or S | Yes |
longitude | Longitude in degrees/min/sec, using " and ' delimiters | Yes |
longitudeRef | E or W | Yes |
Full UDF Source:
/**
* Changes a sexagesimal latitude longitude co-ordinates to decimal format
* v0.9 by John Allen
* v1.0 by Adam Cameron (converted to script, changed return value to be a struct rather than a specially-formatted string)
*
* @param latitude Latitude in degrees/min/sec, using " and ' delimiters (Required)
* @param latitudeRef N or S (Required)
* @param longitude Longitude in degrees/min/sec, using " and ' delimiters (Required)
* @param longitudeRef E or W (Required)
* @return A struct with keys longitude and latitude
* @author John Allen (jallen@figleaf.com)
* @version 1.0, December 20, 2012
*/
function sexagesimalToDecimal(latitude, latitudeRef, longitude, longitudeRef){
var coordinates = {};
var latitudeParts = listToArray(arguments.latitude, "'""");
coordinates.latitude = (
latitudeParts[1] +
(latitudeParts[2] / 60) +
(latitudeParts[3] / 3600)
);
if (arguments.latitudeRef == "S"){
coordinates.latitude *= -1;
}
var longitudeParts = listToArray(arguments.longitude,"'""");
coordinates.longitude = (
longitudeParts[1] +
(longitudeParts[2] / 60) +
(longitudeParts[3] / 3600)
);
if (arguments.longitudeRef == "W"){
coordinates.longitude *= -1;
}
return coordinates;
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016