Convert Coordinates from Decimal Degrees to Degre Minutes Seconds

Sep 15, 2010 at 2:53 AM

Hi Marc,

Got this to work today...
I am using the GoogleMaps API and using Decimal Degrees as my 'version of truth' of projects coordinates on my site.
Using query string parameters, I have a nice 'Project Page' for 200 project sites - along with profile pictures, dynamic GoogleMaps and relative docs (soon to be accordeon-y).
I am for now passing the Lat & Long parameters via the query string as well but may upgrade to getting them via SPServices...

Anywho... Some of the users want to see the coordinates being displayed as part of the 'project profile in Degrees Minutes Seconds meaning
instead of 31.29824
they want 31° 17' 53.66''

(the conversion can be verified on the FCC website at

I obviously want to keep the Lat and Long as 2 single fields, in decimal so I can easily sort, pass via QS, etc...

Let me know if a quick snapshot is advised or if the variable names could be improved.

    <xsl:call-template name="ConvertLatLongfromDec">
     <xsl:with-param name="paramLatLong" select="@Latitude"/>

 <xsl:template name="ConvertLatLongfromDec">
  <xsl:param name="paramLatLong"/>
  <xsl:variable name="IntegerDegree" select="floor($paramLatLong)"/>
  <xsl:variable name="RestDegree" select="($paramLatLong - $IntegerDegree)*60"/>
  <xsl:variable name="IntegerMinutes" select="floor($RestDegree)"/>
  <xsl:variable name="RestMinutes" select="($RestDegree - $IntegerMinutes)*60"/>
  <xsl:variable name="Seconds" select="(round($RestMinutes*100)) div 100"/>

  <!--intermediary calculations results
  <br/><xsl:value-of select="$paramLatLong"/><br/>
  <xsl:value-of select="$IntegerDegree"/><br/>
  <xsl:value-of select="$RestDegree"/><br/>
  <xsl:value-of select="$IntegerMinutes"/><br/>
  <xsl:value-of select="$RestMinutes"/><br/>
  <xsl:value-of select="$Seconds"/>

  <xsl:value-of select="concat($IntegerDegree,'&#176; ', $IntegerMinutes,$dvt_apos,' ',$Seconds,$dvt_apos,$dvt_apos)"/>

Sep 15, 2010 at 3:00 PM

I knoew itwouldn't be straight forward!
For US location, the Longitude will have a negative value so floor() doesn't return what I need.
I was trying to go with an absolute formula but it is apparently not supported....

I am thinking having additional logic checking whether the param passed is >0 or <0...

What do you think?

Sep 15, 2010 at 3:05 PM

I think it's a nice little template! I'll have to dig into it a bit to figure out what the best general solution is. Wouldn't the math be the same and you could then just prepend the '-'?


Sep 15, 2010 at 3:05 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.