Index: branches/Maps0.8/Maps.php |
— | — | @@ -103,6 +103,7 @@ |
104 | 104 | // Autoload the "includes/geocoders/" classes. |
105 | 105 | $geoDir = $incDir . 'geocoders/'; |
106 | 106 | $wgAutoloadClasses['MapsGeonamesGeocoder'] = $geoDir . 'Maps_GeonamesGeocoder.php'; |
| 107 | +$wgAutoloadClasses['MapsGeonamesOldGeocoder'] = $geoDir . 'Maps_GeonamesOldGeocoder.php'; |
107 | 108 | $wgAutoloadClasses['MapsGoogleGeocoder'] = $geoDir . 'Maps_GoogleGeocoder.php'; |
108 | 109 | $wgAutoloadClasses['MapsYahooGeocoder'] = $geoDir . 'Maps_YahooGeocoder.php'; |
109 | 110 | unset( $geoDir ); |
Index: branches/Maps0.8/includes/geocoders/Maps_GeonamesGeocoder.php |
— | — | @@ -0,0 +1,71 @@ |
| 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 LSB in pre-5.3 PHP *sigh*. |
| 22 | + * This is to be refactored as soon as php >=5.3 becomes acceptable. |
| 23 | + * |
| 24 | + * @since 0.8 |
| 25 | + */ |
| 26 | + public static function register() { |
| 27 | + global $egMapsGeoNamesUser; |
| 28 | + |
| 29 | + if ( $egMapsGeoNamesUser != '' ) { |
| 30 | + MapsGeocoders::registerGeocoder( 'geonames', __CLASS__ ); |
| 31 | + } |
| 32 | + |
| 33 | + return true; |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @see MapsGeocoder::getRequestUrl |
| 38 | + * |
| 39 | + * @since 0.7 |
| 40 | + * |
| 41 | + * @param string $address |
| 42 | + * |
| 43 | + * @return string |
| 44 | + */ |
| 45 | + protected function getRequestUrl( $address ) { |
| 46 | + global $egMapsGeoNamesUser; |
| 47 | + return 'http://api.geonames.org/search?q=' . urlencode( $address ) . '&maxRows=1&username=' . urlencode( $egMapsGeoNamesUser ); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @see MapsGeocoder::parseResponse |
| 52 | + * |
| 53 | + * @since 0.7 |
| 54 | + * |
| 55 | + * @param string $address |
| 56 | + * |
| 57 | + * @return array |
| 58 | + */ |
| 59 | + protected function parseResponse( $response ) { |
| 60 | + $lon = self::getXmlElementValue( $response, 'lng' ); |
| 61 | + $lat = self::getXmlElementValue( $response, 'lat' ); |
| 62 | + |
| 63 | + // In case one of the values is not found, return false. |
| 64 | + if ( !$lon || !$lat ) return false; |
| 65 | + |
| 66 | + return array( |
| 67 | + 'lat' => $lat, |
| 68 | + 'lon' => $lon |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | +} |
\ No newline at end of file |
Property changes on: branches/Maps0.8/includes/geocoders/Maps_GeonamesGeocoder.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 73 | + native |