Extension:GooglePlaces
This extension is currently not actively maintained! Although it may still work, any bug reports or feature requests will more than likely be ignored. If you are interested in taking on the task of developing and maintaining this extension, you can request repository ownership. As a courtesy, you may want to contact the author. You should also remove this template and list yourself as maintaining the extension in the page's {{Extension }} infobox. |
GooglePlaces Release status: unmaintained |
|
---|---|
Implementation | Parser function |
Description | Pulls data from the Google Places API into wiki pages |
Author(s) | Ike Hecht (Tosfostalk) |
Latest version | 1.1 (February 2017) |
MediaWiki | 1.25+ |
PHP | 5.3+ |
Database changes | No |
License | GNU General Public License 2.0 or later |
Download | |
|
|
Quarterly downloads | 0 |
Translate the GooglePlaces extension if it is available at translatewiki.net | |
The GooglePlaces extension uses parser functions to pull data from the Google Places API into wiki pages. This extension is not for the faint of heart. Its focus is on functionality and not on ease of use. It works well, but a fair amount of knowledge about the Google Places API is required to get full use of this extension. Basic users can still copy the examples below.
Installation
edit- Download and move the extracted
GooglePlaces
folder to yourextensions/
directory.
Developers and code contributors should install the extension from Git instead, using:cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/GooglePlaces - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'GooglePlaces' ); $wgGooglePlacesAPIKey = /* GOOGLE API KEY GOES HERE */;
- Run the update script which will automatically create the necessary database tables that this extension needs.If downloading with git, you must run
git submodule update --init
from the extension directory. - Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Configuration parameters
edit- $wgGooglePlacesAPIKey
- (Required) Your API key from Google
- $wgGooglePlacesExpiry
- How long to cache the API lookups. Defaults to 10 minutes.
Usage
editNote: With either parser function, either or both parameters may be omitted and the extension will use the value that was contained in the previous parser function call that is on that same page.
The googleplaces
parser function
edit
The googleplaces
parser function allows you to look up a place's details based on that place's Google Place ID. It takes two unnamed parameters.
- The first parameter is the Place ID. You can look that up using this page.
- The second parameter is the path through the API's response that contains the information you need, with each level separated by a
;
. This page contains information about the fields that the API sends.
Examples
edit{{#googleplaces:ChIJKye2O32AhYAReYE_INe4rf4|name}}
→ Wikimedia Foundation Inc.{{#googleplaces:ChIJKye2O32AhYAReYE_INe4rf4|address_fixed;address_city}}
→ SF{{#googleplaces:ChIJKye2O32AhYAReYE_INe4rf4|address_fixed;address_state}}
→ CA{{#googleplaces:ChIJKye2O32AhYAReYE_INe4rf4|formatted_address}}
→ 149 New Montgomery Street, San Francisco, CA 94105, United States{{#googleplaces:ChIJKye2O32AhYAReYE_INe4rf4|formatted_phone_number}}
→ (415) 839-6885{{#googleplaces:ChIJKye2O32AhYAReYE_INe4rf4|geometry;location;lat}}, {{#googleplaces:ChIJKye2O32AhYAReYE_INe4rf4|geometry;location;lng}}
→ 37.786997, -122.399695{{#googleplaces:ChIJKye2O32AhYAReYE_INe4rf4|rating}}
→ 4.4{{#googleplaces:ChIJKye2O32AhYAReYE_INe4rf4|website}}
→ http://wikimediafoundation.org/{{#googleplaces:ChIJKye2O32AhYAReYE_INe4rf4|adr_address}}
→ <span class="street-address">149 New Montgomery Street</span>, <span class="locality">San Francisco</span>, <span class="region">CA</span> <span class="postal-code">94105</span>, <span class="country-name">United States</span>{{#googleplaces:ChIJKye2O32AhYAReYE_INe4rf4|opening_hours;weekday_text;0}}
→ Monday: 9:00 am – 5:00 pm
The googleplacestype
parser function
edit
The googleplacestype
parser function allows you to retrieve particular components of the address_components
API response. It takes two or three unnamed parameters:
- The first parameter is the Place ID. You can look that up using this page.
- The second parameter is the type that the extension should search for. The extension will search through the
address_components
array until it finds an array containing this type. Google uses types contained in this list. - (optional) The third parameter is the field (array key) that the extension should search for, within the array that matches the type that was requested. That is usually either
long_name
orshort_name
. If omitted, the extension will just pick the first value - usuallylong_name
.
Examples
edit{{#googleplacestype:ChIJKye2O32AhYAReYE_INe4rf4|country|long_name}}
→ United States{{#googleplacestype:ChIJKye2O32AhYAReYE_INe4rf4|country|short_name}}
→ US{{#googleplacestype:ChIJKye2O32AhYAReYE_INe4rf4|country}}
→ United States{{#googleplacestype:ChIJKye2O32AhYAReYE_INe4rf4|locality|long_name}}
→ San Francisco{{#googleplacestype:ChIJKye2O32AhYAReYE_INe4rf4|locality|short_name}}
→ SF
Limitations
edit- It should be made more secure, with certificates.
- Caching should be made optional.
- Not all responses from Google (such as responses which are arrays) are easily accessible yet.