Index: trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php |
— | — | @@ -43,8 +43,6 @@ |
44 | 44 | |
45 | 45 | final class MapsGeoFunctions { |
46 | 46 | |
47 | | - // TODO: add support for smart geocoding |
48 | | - // TODO: add coordinate validation |
49 | 47 | function renderGeoDistance( Parser &$parser ) { |
50 | 48 | $args = func_get_args(); |
51 | 49 | |
— | — | @@ -95,33 +93,7 @@ |
96 | 94 | } |
97 | 95 | |
98 | 96 | if ( $start && $end ) { |
99 | | - $northRad1 = deg2rad( $start['lat'] ); |
100 | | - $eastRad1 = deg2rad( $start['lon'] ); |
101 | | - |
102 | | - $cosNorth1 = cos( $northRad1 ); |
103 | | - $cosEast1 = cos( $eastRad1 ); |
104 | | - |
105 | | - $sinNorth1 = sin( $northRad1 ); |
106 | | - $sinEast1 = sin( $eastRad1 ); |
107 | | - |
108 | | - $northRad2 = deg2rad( $end['lat'] ); |
109 | | - $eastRad2 = deg2rad( $end['lon'] ); |
110 | | - |
111 | | - $cosNorth2 = cos( $northRad2 ); |
112 | | - $cosEast2 = cos( $eastRad2 ); |
113 | | - |
114 | | - $sinNorth2 = sin( $northRad2 ); |
115 | | - $sinEast2 = sin( $eastRad2 ); |
116 | | - |
117 | | - $term1 = $cosNorth1 * $sinEast1 - $cosNorth2 * $sinEast2; |
118 | | - $term2 = $cosNorth1 * $cosEast1 - $cosNorth2 * $cosEast2; |
119 | | - $term3 = $sinNorth1 - $sinNorth2; |
120 | | - |
121 | | - $distThruSquared = $term1 * $term1 + $term2 * $term2 + $term3 * $term3; |
122 | | - |
123 | | - $surfaceDistance = 2 * Maps_EARTH_RADIUS * asin( sqrt( $distThruSquared ) / 2 ); |
124 | | - |
125 | | - $output = $surfaceDistance . ' km'; |
| 97 | + $output = self::calculateDistance( $start, $end ) . ' km'; |
126 | 98 | $errorList = $manager->getErrorList(); |
127 | 99 | |
128 | 100 | if ( $errorList != '' ) { |
— | — | @@ -152,7 +124,65 @@ |
153 | 125 | return array( $output, 'noparse' => true, 'isHTML' => true ); |
154 | 126 | } |
155 | 127 | |
| 128 | + public static function renderFindDestination() { |
| 129 | + // TODO |
| 130 | + } |
| 131 | + |
156 | 132 | /** |
| 133 | + * |
| 134 | + * @param unknown_type $start |
| 135 | + * @param unknown_type $end |
| 136 | + */ |
| 137 | + public static function calculateDistance( $start, $end ) { |
| 138 | + $northRad1 = deg2rad( $start['lat'] ); |
| 139 | + $eastRad1 = deg2rad( $start['lon'] ); |
| 140 | + |
| 141 | + $cosNorth1 = cos( $northRad1 ); |
| 142 | + $cosEast1 = cos( $eastRad1 ); |
| 143 | + |
| 144 | + $sinNorth1 = sin( $northRad1 ); |
| 145 | + $sinEast1 = sin( $eastRad1 ); |
| 146 | + |
| 147 | + $northRad2 = deg2rad( $end['lat'] ); |
| 148 | + $eastRad2 = deg2rad( $end['lon'] ); |
| 149 | + |
| 150 | + $cosNorth2 = cos( $northRad2 ); |
| 151 | + $cosEast2 = cos( $eastRad2 ); |
| 152 | + |
| 153 | + $sinNorth2 = sin( $northRad2 ); |
| 154 | + $sinEast2 = sin( $eastRad2 ); |
| 155 | + |
| 156 | + $term1 = $cosNorth1 * $sinEast1 - $cosNorth2 * $sinEast2; |
| 157 | + $term2 = $cosNorth1 * $cosEast1 - $cosNorth2 * $cosEast2; |
| 158 | + $term3 = $sinNorth1 - $sinNorth2; |
| 159 | + |
| 160 | + $distThruSquared = $term1 * $term1 + $term2 * $term2 + $term3 * $term3; |
| 161 | + |
| 162 | + return 2 * Maps_EARTH_RADIUS * asin( sqrt( $distThruSquared ) / 2 ); |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * |
| 167 | + * @param unknown_type $startingCoordinates |
| 168 | + * @param unknown_type $bearing |
| 169 | + * @param unknown_type $distance |
| 170 | + */ |
| 171 | + public static function findDestination( $startingCoordinates, $bearing, $distance ) { |
| 172 | + $angularDistance = $distance / Maps_EARTH_RADIUS; |
| 173 | + $lat = asin( |
| 174 | + sin( $startingCoordinates['lat'] ) * cos( $angularDistance ) + |
| 175 | + cos( $startingCoordinates['lat'] ) * sin( $angularDistance ) * cos( $bearing ) |
| 176 | + ); |
| 177 | + return array( |
| 178 | + 'lat' => $lat, |
| 179 | + 'lon' => $startingCoordinates['lon'] + atan2( |
| 180 | + sin( $bearing ) * sin( $angularDistance ) * cos( $startingCoordinates['lat'] ), |
| 181 | + cos( $angularDistance ) - sin( $startingCoordinates['lat'] ) * sin( $lat ) |
| 182 | + ) |
| 183 | + ); |
| 184 | + } |
| 185 | + |
| 186 | + /** |
157 | 187 | * Returns a boolean indicating if MapsGeocoder is available. |
158 | 188 | */ |
159 | 189 | private static function geocoderIsAvailable() { |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | echo '<b>Warning:</b> You need to have <a href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a> installed in order to use <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a>.'; |
35 | 35 | } |
36 | 36 | else { |
37 | | - define( 'Maps_VERSION', '0.6 a11' ); |
| 37 | + define( 'Maps_VERSION', '0.6 a12' ); |
38 | 38 | |
39 | 39 | // The different coordinate notations. |
40 | 40 | define( 'Maps_COORDS_FLOAT', 'float' ); |