How to Convert DMS (sexagesimal) to Decimal Co-ordinates

I'm trying to get geo-locations (latitudes and longitudes) of photos into a database in a decimal format from EXIF gps data. However, the EXIF fields 'gps latitude' and 'gps longitude' are in a DMS (Degrees, minutes seconds) format. The value of the EXIF field 'gps latitude ref' is either 'N' (north) if the point is north of the equator, or 'S' if it is south of the equator, and 'gps longitude ref' is either 'W' if the point is to the west of the meridian line at Greenwich, or 'E' if it is to the east. The Coldfusion dump of the data looks (for example) like this: 52"15'57.600002 N 3"34'31.799927 W, as in:

<cfimage action="read" source="IMG_6384.jpg" name="myImage" />    
<cfset latitude = ImageGetEXIFTag(myImage,"gps latitude") />
<cfset longitude = ImageGetEXIFTag(myImage,"gps longitude") />
<cfset latref = ImageGetEXIFTag(myImage,"gps latitude ref") />
<cfset lonref = ImageGetEXIFTag(myImage,"gps longitude ref") />

<cfoutput>#latitude# #latref#</cfoutput><br>
<cfoutput>#longitude# #lonref#</cfoutput>

Can anyone come up with a way of converting the DMS values to a decimal number? I think I'm far from being the only person who would find a solution to this useful. I've attached an image file with the required EXIF data.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

there's some JS here which could be adapted or cfscript-ed
it looks like the image you attached does not have any EXIF data in it, so i am going on your description of what the EXIF data looks like:

[code blow uses your LATITUDE and LONGITUDE variables and assumes they are in DD"MM'SS.SSSS format]

<cfset degrees_lat = (listlast(latitude, chr(34)&chr(34))/60 + listgetat(latitude, 2, chr(34)&chr(39)))/60 + listfirst(latitude, chr(34)&chr(39))>

<cfset degrees_lng = (listlast(longitude, chr(34)&chr(34))/60 + listgetat(longitude, 2, chr(34)&chr(39)))/60 + listfirst(longitude, chr(34)&chr(39))>

goholsAuthor Commented:
Just checked and it looks like EE has stripped out the EXIF and IPTC data. The file with these intact is at

I tried the solution from azadisaryev and it's probably essentially ok, but it throws an error:

" The value 15'57.600002 cannot be converted to a number. "
sorry, a typo in my code:
i have chr(34)&chr(34), but it should be chr(34)&chr(39)

so, correct code is:

<cfset degrees_lat = (listlast(latitude, chr(34)&chr(39))/60 + listgetat(latitude, 2, chr(34)&chr(39)))/60 + listfirst(latitude, chr(34)&chr(39))>

<cfset degrees_lng = (listlast(longitude, chr(34)&chr(39))/60 + listgetat(longitude, 2, chr(34)&chr(39)))/60 + listfirst(longitude, chr(34)&chr(39))>

fiy, in case you were wondering, chr(34) is an ascii code for " (double quote) and chr(39) for ' (single quote)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
goholsAuthor Commented:
Thanks, Azadisaryev - that works a treat.

Anyone using this should bear in mind that if the value of the IPTC tag 'gps latitude ref' is S, or if the value of 'gps longitude ref' is E, the decimal version of the co-ordinate will be a minus value so you will need to append the '-' character to the start of the number.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.