<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Converting latitude/longitude with PHP</title>
	<atom:link href="http://www.super-cooper.com/archive/2004/11/16/convert-lat-long-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.super-cooper.com/archive/2004/11/16/convert-lat-long-php/</link>
	<description>Python, GIS, and a sprinkling of mindless drivel from Chad Cooper</description>
	<lastBuildDate>Fri, 22 Jul 2011 20:58:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: D</title>
		<link>http://www.super-cooper.com/archive/2004/11/16/convert-lat-long-php/comment-page-1/#comment-368</link>
		<dc:creator>D</dc:creator>
		<pubDate>Wed, 27 Jul 2005 00:21:53 +0000</pubDate>
		<guid isPermaLink="false">http://super-cooper.com/?p=61#comment-368</guid>
		<description>Added n/s e/w for hemisphere, and get lat/long from request...saved me lots of work by the way...thanks!!
&lt;?php 
// convert decimal degrees to degrees/minutes/seconds \\ 
// some definitions: 
// DD=decimal degrees 
// DMS=degrees/minutes/seconds 
// 
// How this works: 
// Say you have 32.872352 lat and -91.632563 long 
// The whole units of the decimal will remain the same, so 
// 1) multiply the decimal by 60 (0.872352 * 60 = 52.34112), the whole number becomes the minutes (52) 
// 2) take the remaining decimal (0.34112) and multiply by 60, this is now the seconds, round this to two decimal places (0.34221 * 60 = 20.53) 
// 3) string them all together 32 52 20.53 
// 
// ** LATITUDE ** \\ 
// DEGREES \\ 
// get integer value of latitude from db -&gt; where $lat_dd is a floating point number like 32.872352
$lat_dd = $_REQUEST[&#039;lat&#039;];
$long_dd = $_REQUEST[&#039;long&#039;];
if ($lat_dd&lt;0) $lat_hemi=&quot;S&quot;;
else $lat_hemi=&quot;N&quot;;
if ($long_dd&lt;0) $long_hemi=&quot;W&quot;;
else $long_hemi = &quot;E&quot;;
$lat_dd=abs($lat_dd);
$long_dd=abs($long_dd);
$lat_dd_int = intval(&quot;$lat_dd&quot;); 
// MINUTES \\ 
// get DD minutes (whats after the decimal point)-&gt; Lat DD floating point - lat DD integer 
$lat_dd_m = $lat_dd - $lat_dd_int; 
// get DMS minutes as floating point -&gt; 60 * DD minutes floating 
$lat_dms_m_float = 60 * $lat_dd_m; 
// get int value of lat DMS floating point 
$lat_dms_m_int = intval(&quot;$lat_dms_m_float&quot;); 
// SECONDS \\ 
// get DD seconds -&gt; DMS minutes floating - DMS minutes integer 
$lat_dd_s = $lat_dms_m_float - $lat_dms_m_int; 
// convert DD secs to DMS secs -&gt; 60 * DD seconds 
$lat_dms_s = 60 * $lat_dd_s; 
// ** LONGITUDE ** \\ 
// DEGREES \\ 
// get integer value of longitude from db -&gt; where $long_dd is a floating point number like -91.632563 
// this number remains negative 
$long_dd_int = intval(&quot;$long_dd&quot;); 
// MINUTES \\ 
// get DD minutes (whats after the decimal point)-&gt; Long DD floating point - long DD integer 
// use abs to get rid of the negative sign 
$long_dd_m = abs($long_dd - $long_dd_int); 
// get DMS minutes as floating point -&gt; 60 * DD minutes floating 
$long_dms_m_float = 60 * $long_dd_m; 
// get int value of long DMS floating 
$long_dms_m_int = intval(&quot;$long_dms_m_float&quot;); 
// SECONDS \\ 
// get DD seconds -&gt; DMS minutes floating - DMS minutes integer 
$long_dd_s = $long_dms_m_float - $long_dms_m_int; 
// convert DD secs to DMS secs -&gt; 60 * DD seconds 
$long_dms_s = 60 * $long_dd_s; 
// end conversion of lat/long \\ 
// next just echo the output with the degree/minute/second symbols in place 
?&gt; 
Latitude: &lt;?php echo $lat_dd_int; ?&gt;&#176; &lt;?php echo $lat_dms_m_int; ?&gt;&#8217; &lt;?php echo round($lat_dms_s, 2); ?&gt;&#8221;&lt;?php echo ($lat_hemi); ?&gt;
Longitude: &lt;?php echo $long_dd_int; ?&gt;&#176; &lt;?php echo $long_dms_m_int; ?&gt;&#8217; &lt;?php echo round($long_dms_s, 2); ?&gt;&#8221;&lt;?php echo ($long_hemi); ?&gt;</description>
		<content:encoded><![CDATA[<p>Added n/s e/w for hemisphere, and get lat/long from request&#8230;saved me lots of work by the way&#8230;thanks!!<br />
< ?php<br />
// convert decimal degrees to degrees/minutes/seconds \\<br />
// some definitions:<br />
// DD=decimal degrees<br />
// DMS=degrees/minutes/seconds<br />
//<br />
// How this works:<br />
// Say you have 32.872352 lat and -91.632563 long<br />
// The whole units of the decimal will remain the same, so<br />
// 1) multiply the decimal by 60 (0.872352 * 60 = 52.34112), the whole number becomes the minutes (52)<br />
// 2) take the remaining decimal (0.34112) and multiply by 60, this is now the seconds, round this to two decimal places (0.34221 * 60 = 20.53)<br />
// 3) string them all together 32 52 20.53<br />
//<br />
// ** LATITUDE ** \\<br />
// DEGREES \\<br />
// get integer value of latitude from db -> where $lat_dd is a floating point number like 32.872352<br />
$lat_dd = $_REQUEST['lat'];<br />
$long_dd = $_REQUEST['long'];<br />
if ($lat_dd&lt;0) $lat_hemi="S";<br />
else $lat_hemi="N";<br />
if ($long_dd&lt;0) $long_hemi="W";<br />
else $long_hemi = "E";<br />
$lat_dd=abs($lat_dd);<br />
$long_dd=abs($long_dd);<br />
$lat_dd_int = intval("$lat_dd");<br />
// MINUTES \\<br />
// get DD minutes (whats after the decimal point)-> Lat DD floating point &#8211; lat DD integer<br />
$lat_dd_m = $lat_dd &#8211; $lat_dd_int;<br />
// get DMS minutes as floating point -> 60 * DD minutes floating<br />
$lat_dms_m_float = 60 * $lat_dd_m;<br />
// get int value of lat DMS floating point<br />
$lat_dms_m_int = intval(&#8220;$lat_dms_m_float&#8221;);<br />
// SECONDS \\<br />
// get DD seconds -> DMS minutes floating &#8211; DMS minutes integer<br />
$lat_dd_s = $lat_dms_m_float &#8211; $lat_dms_m_int;<br />
// convert DD secs to DMS secs -> 60 * DD seconds<br />
$lat_dms_s = 60 * $lat_dd_s;<br />
// ** LONGITUDE ** \\<br />
// DEGREES \\<br />
// get integer value of longitude from db -> where $long_dd is a floating point number like -91.632563<br />
// this number remains negative<br />
$long_dd_int = intval(&#8220;$long_dd&#8221;);<br />
// MINUTES \\<br />
// get DD minutes (whats after the decimal point)-> Long DD floating point &#8211; long DD integer<br />
// use abs to get rid of the negative sign<br />
$long_dd_m = abs($long_dd &#8211; $long_dd_int);<br />
// get DMS minutes as floating point -> 60 * DD minutes floating<br />
$long_dms_m_float = 60 * $long_dd_m;<br />
// get int value of long DMS floating<br />
$long_dms_m_int = intval(&#8220;$long_dms_m_float&#8221;);<br />
// SECONDS \\<br />
// get DD seconds -> DMS minutes floating &#8211; DMS minutes integer<br />
$long_dd_s = $long_dms_m_float &#8211; $long_dms_m_int;<br />
// convert DD secs to DMS secs -> 60 * DD seconds<br />
$long_dms_s = 60 * $long_dd_s;<br />
// end conversion of lat/long \\<br />
// next just echo the output with the degree/minute/second symbols in place<br />
?><br />
Latitude: < ?php echo $lat_dd_int; ?>&#176; < ?php echo $lat_dms_m_int; ?>&#8217; < ?php echo round($lat_dms_s, 2); ?>&#8221;< ?php echo ($lat_hemi); ?><br />
Longitude: < ?php echo $long_dd_int; ?>&#176; < ?php echo $long_dms_m_int; ?>&#8217; < ?php echo round($long_dms_s, 2); ?>&#8221;< ?php echo ($long_hemi); ?></p>
]]></content:encoded>
	</item>
</channel>
</rss>

