Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -99,7 +99,7 @@ |
100 | 100 | $wgAutoloadClasses['iMappingParserFunction'] = $incDir . 'iMappingParserFunction.php'; // TODO |
101 | 101 | |
102 | 102 | // Geocoders at "Includes/Geocoders/". |
103 | | - $geoDir = $incDir . 'Geocoders/'; |
| 103 | + $geoDir = $incDir . 'geocoders/'; |
104 | 104 | $wgAutoloadClasses['MapsGeonamesGeocoder'] = $geoDir . 'Maps_GeonamesGeocoder.php'; |
105 | 105 | $wgAutoloadClasses['MapsGoogleGeocoder'] = $geoDir . 'Maps_GoogleGeocoder.php'; |
106 | 106 | $wgAutoloadClasses['MapsYahooGeocoder'] = $geoDir . 'Maps_YahooGeocoder.php'; |
Index: trunk/extensions/Maps/includes/geocoders/Maps_GoogleGeocoder.php |
— | — | @@ -0,0 +1,81 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class for geocoding requests with the Google Geocoding Service (v2). |
| 6 | + * |
| 7 | + * Webservice documentation: http://code.google.com/apis/maps/documentation/services.html#Geocoding_Direct |
| 8 | + * |
| 9 | + * @file Maps_GoogleGeocoder.php |
| 10 | + * @ingroup Maps |
| 11 | + * @ingroup Geocoders |
| 12 | + * |
| 13 | + * @author Jeroen De Dauw |
| 14 | + * @author Sergey Chernyshev |
| 15 | + */ |
| 16 | +final class MapsGoogleGeocoder extends MapsGeocoder { |
| 17 | + |
| 18 | + /** |
| 19 | + * Registeres the geocoder. |
| 20 | + * |
| 21 | + * No LST in pre-5.3 PHP *sigh*. |
| 22 | + * This is to be refactored as soon as php >=5.3 becomes acceptable. |
| 23 | + * |
| 24 | + * @since 0.7 |
| 25 | + */ |
| 26 | + public static function register() { |
| 27 | + MapsGeocoders::registerGeocoder( 'google', __CLASS__ ); |
| 28 | + return true; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @see MapsGeocoder::getRequestUrl |
| 33 | + * |
| 34 | + * @since 0.7 |
| 35 | + * |
| 36 | + * @param string $address |
| 37 | + * |
| 38 | + * @return string |
| 39 | + */ |
| 40 | + protected function getRequestUrl( $address ) { |
| 41 | + global $egGoogleMapsKey; |
| 42 | + return 'http://maps.google.com/maps/geo?q=' . urlencode( $address ) . '&output=csv&key=' . urlencode( $egGoogleMapsKey ); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @see MapsGeocoder::parseResponse |
| 47 | + * |
| 48 | + * @since 0.7 |
| 49 | + * |
| 50 | + * @param string $address |
| 51 | + * |
| 52 | + * @return array |
| 53 | + */ |
| 54 | + protected function parseResponse( $response ) { |
| 55 | + // Check the Google Geocoder API Response code to ensure success. |
| 56 | + if ( substr( $response, 0, 3 ) == '200' ) { |
| 57 | + $result = explode( ',', $response ); |
| 58 | + |
| 59 | + // $precision = $result[1]; |
| 60 | + |
| 61 | + return array( |
| 62 | + 'lat' => $result[2], |
| 63 | + 'lon' => $result[3] |
| 64 | + ); |
| 65 | + } |
| 66 | + else { // When the request fails, return false. |
| 67 | + return false; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @see MapsGeocoder::getOverrides |
| 73 | + * |
| 74 | + * @since 0.7 |
| 75 | + * |
| 76 | + * @return array |
| 77 | + */ |
| 78 | + public function getOverrides() { |
| 79 | + return array( 'googlemaps2', 'googlemaps3' ); |
| 80 | + } |
| 81 | + |
| 82 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Maps/includes/geocoders/Maps_GoogleGeocoder.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 83 | + native |
Index: trunk/extensions/Maps/includes/geocoders/Maps_GeonamesGeocoder.php |
— | — | @@ -0,0 +1,65 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class for geocoding requests with the GeoNames webservice. |
| 6 | + * |
| 7 | + * GeoNames Web Services Documentation: http://www.geonames.org/export/geonames-search.html |
| 8 | + * |
| 9 | + * @file Maps_GeonamesGeocoder.php |
| 10 | + * @ingroup Maps |
| 11 | + * @ingroup Geocoders |
| 12 | + * |
| 13 | + * @author Jeroen De Dauw |
| 14 | + * Thanks go to Joel Natividad for pointing me to the GeoNames services. |
| 15 | + */ |
| 16 | +final class MapsGeonamesGeocoder extends MapsGeocoder { |
| 17 | + |
| 18 | + /** |
| 19 | + * Registeres the geocoder. |
| 20 | + * |
| 21 | + * No LST in pre-5.3 PHP *sigh*. |
| 22 | + * This is to be refactored as soon as php >=5.3 becomes acceptable. |
| 23 | + * |
| 24 | + * @since 0.7 |
| 25 | + */ |
| 26 | + public static function register() { |
| 27 | + MapsGeocoders::registerGeocoder( 'geonames', __CLASS__ ); |
| 28 | + return true; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @see MapsGeocoder::getRequestUrl |
| 33 | + * |
| 34 | + * @since 0.7 |
| 35 | + * |
| 36 | + * @param string $address |
| 37 | + * |
| 38 | + * @return string |
| 39 | + */ |
| 40 | + protected function getRequestUrl( $address ) { |
| 41 | + return 'http://ws.geonames.org/search?q=' . urlencode( $address ) . '&maxRows=1&style=SHORT'; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @see MapsGeocoder::parseResponse |
| 46 | + * |
| 47 | + * @since 0.7 |
| 48 | + * |
| 49 | + * @param string $address |
| 50 | + * |
| 51 | + * @return array |
| 52 | + */ |
| 53 | + protected function parseResponse( $response ) { |
| 54 | + $lon = self::getXmlElementValue( $response, 'lng' ); |
| 55 | + $lat = self::getXmlElementValue( $response, 'lat' ); |
| 56 | + |
| 57 | + // In case one of the values is not found, return false. |
| 58 | + if ( !$lon || !$lat ) return false; |
| 59 | + |
| 60 | + return array( |
| 61 | + 'lat' => $lat, |
| 62 | + 'lon' => $lon |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Maps/includes/geocoders/Maps_GeonamesGeocoder.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 67 | + native |
Index: trunk/extensions/Maps/includes/geocoders/Maps_YahooGeocoder.php |
— | — | @@ -0,0 +1,76 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class for geocoding requests with the Yahoo! Geocoding Service. |
| 6 | + * |
| 7 | + * Yahoo! Geocoding Service info: http://developer.yahoo.com/geo/geoplanet/ |
| 8 | + * |
| 9 | + * @file Maps_YahooGeocoder.php |
| 10 | + * @ingroup Maps |
| 11 | + * @ingroup Geocoders |
| 12 | + * |
| 13 | + * @author Jeroen De Dauw |
| 14 | + */ |
| 15 | +final class MapsYahooGeocoder extends MapsGeocoder { |
| 16 | + |
| 17 | + /** |
| 18 | + * Registeres the geocoder. |
| 19 | + * |
| 20 | + * No LST in pre-5.3 PHP *sigh*. |
| 21 | + * This is to be refactored as soon as php >=5.3 becomes acceptable. |
| 22 | + * |
| 23 | + * @since 0.7 |
| 24 | + */ |
| 25 | + public static function register() { |
| 26 | + MapsGeocoders::registerGeocoder( 'yahoo', __CLASS__ ); |
| 27 | + return true; |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @see MapsGeocoder::getRequestUrl |
| 32 | + * |
| 33 | + * @since 0.7 |
| 34 | + * |
| 35 | + * @param string $address |
| 36 | + * |
| 37 | + * @return string |
| 38 | + */ |
| 39 | + protected function getRequestUrl( $address ) { |
| 40 | + global $egYahooMapsKey; |
| 41 | + return "http://where.yahooapis.com/v1/places.q('" . urlencode( $address ) . "')?appid=" . urlencode( $egYahooMapsKey ) . '&format=xml'; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @see MapsGeocoder::parseResponse |
| 46 | + * |
| 47 | + * @since 0.7 |
| 48 | + * |
| 49 | + * @param string $address |
| 50 | + * |
| 51 | + * @return array |
| 52 | + */ |
| 53 | + protected function parseResponse( $response ) { |
| 54 | + $lon = self::getXmlElementValue( $response, 'longitude' ); |
| 55 | + $lat = self::getXmlElementValue( $response, 'latitude' ); |
| 56 | + |
| 57 | + // In case one of the values is not found, return false. |
| 58 | + if ( !$lon || !$lat ) return false; |
| 59 | + |
| 60 | + return array( |
| 61 | + 'lat' => $lat, |
| 62 | + 'lon' => $lon |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @see MapsGeocoder::getOverrides |
| 68 | + * |
| 69 | + * @since 0.7 |
| 70 | + * |
| 71 | + * @return array |
| 72 | + */ |
| 73 | + public function getOverrides() { |
| 74 | + return array( 'yahoomaps' ); |
| 75 | + } |
| 76 | + |
| 77 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Maps/includes/geocoders/Maps_YahooGeocoder.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 78 | + native |