Extension:GoogleGeocode

From mediawiki.org
MediaWiki extensions manual
GoogleGeocode
Release status: beta
Implementation Parser function
Description MediaWiki wrapper around the Google Geocode API
Author(s) Ike Hecht (Tosfostalk)
Latest version 0.1.0 (November 2015)
MediaWiki 1.23+
PHP 5.3+
Database changes No
Composer mediawiki/google-geocode
License GNU General Public License 2.0 or later
Download
  • $wgGoogleGeocodeExpiry
  • $wgGoogleGeocodeDelimiter
Quarterly downloads 1 (Ranked 143rd)
Translate the GoogleGeocode extension if it is available at translatewiki.net

The GoogleGeocode extension is a MediaWiki wrapper around the GoogleMapsGeocoder PHP wrapper around the Google Maps Geocoding API. It is capable of looking up a given address, and obtaining information about it, such as its geocoordinates.

Installation[edit]

  • Download and move the extracted GoogleGeocode folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/GoogleGeocode
  • Only when installing from Git, run Composer to install PHP dependencies, by issuing composer install --no-dev in the extension directory. (See task T173141 for potential complications.)
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'GoogleGeocode' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
When installing from Git, please note that this extension requires Composer.

So, after installation from git, change to the directory containing the extension e.g. ".../extensions/GoogleGeocode/" and run composer install --no-dev, or when updating: composer update --no-dev.

Alternatively as well as preferably add the line "extensions/GoogleGeocode/composer.json" to the "composer.local.json" file in the root directory of your wiki like e.g.
{
	"extra": {
		"merge-plugin": {
			"include": [
				"extensions/GoogleGeocode/composer.json"
			]
		}
	}
}
Now run composer update --no-dev.

Configuration parameters[edit]

$wgGoogleGeocodeAPIKey
API key. You should probably obtain one from Google.
$wgGoogleGeocodeExpiry
Time (in seconds) to cache the data received from Google. Adjust to keep within the API's usage limits. Defaults to: 600 (10 minutes).
$wgGoogleGeocodeDelimiter
Delimiter to use between elements of returned arrays. Defaults to: ;.

Usage[edit]

The googlegeocode parser function takes three parameters, in the form of {{#googlegeocode:Search term|Component|Path}}:

Search term
The search term to send to the API. This would usually be an address or establishment name.
Component
Component to request from Google. Good candidates for this would be lat, lng, route, locality, country... See the documentation for more examples.
Path
(optional, advanced) Can be set to the desired type of component result to obtain. Can be set to short_name, long_name or types. Defaults to: long_name.

If either of the first two parameters are omitted, the extension will use the value previously entered on that page.

Examples[edit]

  • {{#googlegeocode:1600 Amphitheatre Parkway, Mountain View, CA|lat}} --> 37.4224504
  • {{#googlegeocode:1600 Amphitheatre Parkway, Mountain View, CA|lng}} --> -122.0840859
  • {{#googlegeocode:1600 Amphitheatre Parkway, Mountain View, CA|locality}} --> Mountain View
  • {{#googlegeocode:Google, CA|locality}} --> Mountain View
  • {{#googlegeocode:|country|short_name}} --> US
  • {{#googlegeocode:}} --> United States

See also[edit]