Extension:Google Maps/Installation

From MediaWiki.org
Jump to navigation Jump to search

Introduction - Installation - Editor's Map icon - Coding instructions - Compatibility - Languages - Developers - Talk

Note: Version see SVN works with MediaWiki 1.5 and up. It is recommended over all previous versions. Note, however, the Editor's Map will only be available if you're using MediaWiki 1.6 or greater.

Basic Installation in Three Easy Steps[edit]

  1. Go sign up for a Google Maps API key from here.
  2. Download this file, and unzip it into your "extensions" directory: http://www.evanmiller.org/maps/GoogleMaps-see SVN.zip
  3. it should create a "GoogleMaps" folder with a few files.
  4. Add this to the end of LocalSettings.php:
$wgGoogleMapsKey = "your key from step 1 goes here";
require_once( "$IP/extensions/GoogleMaps/GoogleMaps.php" );
$IP stands for the Installation Path (or "directory") of your MediaWiki installation, the same directory that holds LocalSettings.php, index.php etc..

If all went well, you should be good to go! See Extension:Google Maps/Usage for how to test it out.

Basic Upgrade[edit]

From 0.6, 0.7, or 0.8[edit]

Just delete your extensions/GoogleMaps/ directory and then get a fresh copy of http://www.mediawiki.org/wiki/Special:ExtensionDistributor/GoogleMaps, and unzip it into your "extensions" folder.

From 0.5 or 0.4[edit]

You need to delete the file extensions/GoogleMaps.php, and update LocalSettings.php to have this:

require_once( "$IP/extensions/GoogleMaps/GoogleMaps.php" );

Then unzip http://www.evanmiller.org/maps/GoogleMaps-see SVN.zip inside your extensions directory, and you should be good to go.

From earlier versions[edit]

See Extension:Google Maps/Old versions#Upgrading first.


Basic setup[edit]

Odds are you don't want your maps to be centered in Williamstown, Massachusetts by default. You can change the default co-ordinates by adding this to LocalSettings.php:

$wgGoogleMapsDefaults = array( "lat" => 13.3801841, "lon" => -45.8103148 );

Where of course you insert your own co-ordinates. Use the Editor's Map to find the position you want.

You can also change the other default map attributes with $wgGoogleMapsDefaults. Just add the appropriate key/value pairs. Some useful ones:

  • zoom: The default zoom level, between 1 (far out) and 18 (close up)
  • width: The default width of maps in pixels
  • height: The default height of maps in pixels
  • icon: The default URL of the map's icons for place marks.

You can actually override any map tag attributes. In addition, these keys will change the behavior of the editor's map:

  • units (unit of measure for calculating distances. Legal values are meters (default) and miles)
  • version (version of the Google Maps API to use; defaults to 2.85)
  • color (the default color of paths in RGB hex format, e.g. "#000000")
  • precision (number of decimal places to use with co-ordinates; defaults to 6)

Changing the default settings on a per-page basis[edit]

Now you might be thinking, it sure would be useful to set different default co-ordinates for different pages; say, maps created on the "New York City" page would be centered on the Big Apple while maps on the "Boston" page would automatically focus on Massachusetts. Well, now you can do that! Just specify an intermediate key with the page name you want to apply the values to. For example:

$wgGoogleMapsDefaults = array( 
               "Boston" => array( "lat" => 42.358333, "lon" => -71.060278 ),
               "New York City" => array( "lat" => "40.714167", "lon" => -74.006389 ),
               "lat" => 13.8442, "lon" => -45.1831); # these apply to all other pages

You can specify any map attribute this way.

Draw custom paths[edit]

Good news! The MediaWiki folks accepted my patch, so if you're running MediaWiki 1.9 and using Google Maps Extension 0.7.5 or later, colored paths should work out-of-the-box. Otherwise, read on.

This part is a small pain in the neck. Internet Explorer won't let you draw paths unless there's a special tag at the very beginning of the page. Unfortunately, this means you'll need to muck around with other files in your MediaWiki installation. But don't worry, it'll only take a minute. Just add the stuff in red you see below.

1. Change line 982-ish in includes/OutputPage.php from this:

 $ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";

To this:

 $ret .= "<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";

2. Change line 54-ish in skins/MonoBook.php (or YourSkinName.php if you use another default skin) from this:

 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php $this->text('lang') ?>" lang="<?php $this->text('lang') ?>" dir="<?php $this->text('dir') ?>">

To this:

 <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php $this->text('lang') ?>" lang="<?php $this->text('lang') ?>" dir="<?php $this->text('dir') ?>">

3. Now you need to tell the extension that paths are working. In LocalSettings.php (anywhere, but close to your other extension configuration is a good idea), add this line:

$wgGoogleMapsEnablePaths = true;

That's it! Now you can draw on your maps to heart's content.

Disabling the search box[edit]

(0.7.5 and up) Unfortunately, the business search and address search don't work everywhere, mainly just the U.S., Canada, Japan, and a few countries in Western Europe. If you want to disable these search features on your wiki, just open up LocalSettings.php and set the values of "geocoder" and "localsearch" in the $wgGoogleMapsDefaults variable to false, like this:

$wgGoogleMapsDefaults = array( "geocoder" => false, "localsearch" => false );

If you want to disable local (business) searches but keep the geo-coder, you would use this:

$wgGoogleMapsDefaults = array( "geocoder" => true, "localsearch" => false );

You can also disable or enable these features on a per-page basis, as described above.

Disabling the Editor's Map[edit]

(0.7.5 and up) Some people think the Editor's Map gets in the way. To disable it altogether, just add this to LocalSettings.php:

$wgGoogleMapsDisableEditorsMap = true;

'Italic text'

Multiple API keys[edit]

In the past, if your wiki was accessible from multiple URLs, then you had to choose only one of them to work with Google Maps Extension. No more! Just add an array called $wgGoogleMapsKeys to LocalSettings.php with domains as the keys and your Google Maps API key as the value, e.g.:

$wgGoogleMapsKeys = array( "wiki.mycoolsite.com" => "ABQIAAAA5nNsCplt4ROF-lZxSn8x7BTr7dBAVb7q3Yj",
                           "www.mycoolsite.com/wiki" => "ABQIA32j2islt4ROF-lZxSn8x7dssjdfsoaOE323ssa" );

The extension will use the appropriate one based on where it receives requests from. NOTE however that MediaWiki's caching mechanism may interfere with this. If you experience problems you can turn off MediaWiki's cache, but you will suffer a performance hit. To disable the cache, put this in LocalSettings.php:

$wgEnableParserCache = false;

Multiple Wikis[edit]

If there are several sub domains under a domain then one needs to get the Google Maps API key only once and just needs to edit the LocalSettings.php for the sub domain(s) for which one wants to enable Google Maps.


Problems? First check the Extension:Google Maps/Compatibility page to see whethere it's supposed to work on your system.

While you're tinkering with settings, you may need to try a couple tricks. One problem is that a new map will be generated only when you save a change to the page that contains the <googlemap>. If you want to test changes to the server just by hitting "Reload" in your browser, add "?action=purge" to the end of the URL. That will ensure that the entire page is generated fresh every time you load it, rather than every time you save it. Alternatively, you can switch off server-side caching altogether by adding this line to LocalSettings.php:

$wgEnableParserCache = false;