<?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
    <title>Posteet: maps</title> 
    <link>http://www.posteet.com/</link> 
    <description>Recent posteets posted to Posteet</description>
    <ttl>60</ttl>

    
    <item>
        <title>Distance between two points (given the latitude/longitude of those points) FUNCTION for MySQL</title>
        <link>http://www.posteet.com/view/1555</link>
        <description>
        <![CDATA[<pre>Great circle distance
Find the distance in kilometres between two points on the surface of the earth. This is just the sort of problem stored functions were made for. For a first order approximation, ignore deviations of the earth's surface from the perfectly spherical. Then the distance in radians is given by a number of trigonometric formulas. ACOS and COS behave reasonably:

             COS(lat1-lat2)*(1+COS(lon1-lon2)) - COS(lat1+lat2)*(1-COS(lon1-lon2))
rads = ACOS( --------------------------------------------------------------------- )
                                              2

We need to convert degrees latitude and longitude to radians, and we need to know the length in km of one radian on the earth's surface, which is 6378.388. The function:

set log_bin_trust_function_creators=TRUE;

DROP FUNCTION IF EXISTS GeoDistKM;
DELIMITER |
CREATE FUNCTION GeoDistKM( lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT ) RETURNS float
BEGIN
  DECLARE pi, q1, q2, q3 FLOAT;
  DECLARE rads FLOAT DEFAULT 0;
  SET pi = PI();
  SET lat1 = lat1 * pi / 180;
  SET lon1 = lon1 * pi / 180;
  SET lat2 = lat2 * pi / 180;
  SET lon2 = lon2 * pi / 180;
  SET q1 = COS(lon1-lon2);
  SET q2 = COS(lat1-lat2);
  SET q3 = COS(lat1+lat2);
  SET rads = ACOS( 0.5*((1.0+q1)*q2 - (1.0-q1)*q3) ); 
  RETURN 6378.388 * rads;
END;
|
DELIMITER ;

-- toronto to montreal (505km):
select geodistkm(43.6667,-79.4167,45.5000,-73.5833);
+----------------------------------------------+
| geodistkm(43.6667,-79.4167,45.5000,-73.5833) |
+----------------------------------------------+
|                           505.38836669921875 |
+----------------------------------------------+</pre> <a href="http://www.posteet.com/tags/distance">[distance]</a>  <a href="http://www.posteet.com/tags/function">[function]</a>  <a href="http://www.posteet.com/tags/lat">[lat]</a>  <a href="http://www.posteet.com/tags/latitude">[latitude]</a>  <a href="http://www.posteet.com/tags/lng">[lng]</a>  <a href="http://www.posteet.com/tags/longitude">[longitude]</a>  <a href="http://www.posteet.com/tags/maps">[maps]</a>  <a href="http://www.posteet.com/tags/mysql">[mysql]</a> ]]>        </description>
        <dc:creator>spirit</dc:creator>
        <pubDate>Mon, 09 Feb 2009 20:07:38 +0100</pubDate>

            <category>distance</category>
            <category>function</category>
            <category>lat</category>
            <category>latitude</category>
            <category>lng</category>
            <category>longitude</category>
            <category>maps</category>
            <category>mysql</category>
    
    </item>

  
    <item>
        <title>Distance between two points (given the latitude/longitude of those points) in PHP</title>
        <link>http://www.posteet.com/view/1554</link>
        <description>
        <![CDATA[<pre>function distance($lat1, $lon1, $lat2, $lon2, $unit) { 

  $theta = $lon1 - $lon2; 
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); 
  $dist = acos($dist); 
  $dist = rad2deg($dist); 
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);

  if ($unit == &quot;K&quot;) {
    return ($miles * 1.609344); 
  } else if ($unit == &quot;N&quot;) {
      return ($miles * 0.8684);
    } else {
        return $miles;
      }
}

echo distance(32.9697, -96.80322, 29.46786, -98.53506, &quot;m&quot;) . &quot; miles&lt;br&gt;&quot;;
echo distance(32.9697, -96.80322, 29.46786, -98.53506, &quot;k&quot;) . &quot; kilometers&lt;br&gt;&quot;;
echo distance(32.9697, -96.80322, 29.46786, -98.53506, &quot;n&quot;) . &quot; nautical miles&lt;br&gt;&quot;;</pre> <a href="http://www.posteet.com/tags/distance">[distance]</a>  <a href="http://www.posteet.com/tags/lat">[lat]</a>  <a href="http://www.posteet.com/tags/latitude">[latitude]</a>  <a href="http://www.posteet.com/tags/lng">[lng]</a>  <a href="http://www.posteet.com/tags/longitude">[longitude]</a>  <a href="http://www.posteet.com/tags/maps">[maps]</a>  <a href="http://www.posteet.com/tags/php">[php]</a> ]]>        </description>
        <dc:creator>spirit</dc:creator>
        <pubDate>Mon, 09 Feb 2009 20:04:34 +0100</pubDate>

            <category>distance</category>
            <category>lat</category>
            <category>latitude</category>
            <category>lng</category>
            <category>longitude</category>
            <category>maps</category>
            <category>php</category>
    
    </item>

  
    <item>
        <title>Get Latitude and Longitude values from Google Maps</title>
        <link>http://www.posteet.com/view/1412</link>
        <description>
        <![CDATA[<pre>javascript:void(prompt('',gApplication.getMap().getCenter()));</pre> <a href="http://www.posteet.com/tags/gmaps">[gmaps]</a>  <a href="http://www.posteet.com/tags/javascript">[javascript]</a>  <a href="http://www.posteet.com/tags/latitude">[latitude]</a>  <a href="http://www.posteet.com/tags/longitude">[longitude]</a>  <a href="http://www.posteet.com/tags/maps">[maps]</a> ]]>        </description>
        <dc:creator>spirit</dc:creator>
        <pubDate>Sat, 03 Jan 2009 17:30:18 +0100</pubDate>

            <category>gmaps</category>
            <category>javascript</category>
            <category>latitude</category>
            <category>longitude</category>
            <category>maps</category>
    
    </item>


</channel>
</rss>
