Difference between revisions of "Geocode function"

From Maps for MediaWiki
(Created page with "The Maps extension supports geocoding at all places where you can specify a location. You can access this functionality directly using the <code>#geocode</code> parser fun...")
 
 
Line 32: Line 32:
| format
| format
| dms (changeable in [[Configuration|wiki config]] with <code>egMapsCoordinateNotation</code>)
| dms (changeable in [[Configuration|wiki config]] with <code>egMapsCoordinateNotation</code>)
| The format to convert the coordinates to. See [[Maps/Coordinate_formats|available coordinate formats]]
| The format to convert the coordinates to. See [[Coordinate_formats|available coordinate formats]]
|-
|-
| directional
| directional

Latest revision as of 23:34, 7 May 2020

The Maps extension supports geocoding at all places where you can specify a location. You can access this functionality directly using the #geocode parser function, which gives you the coordinates for the address you provide to it.

Syntax[edit | edit source]

{{#geocode:<your address>|format=<coordinate format>|directional=<yes/no>}}

Usecases[edit | edit source]

You can use #geocode inline with some text or in an infobox.

The Brandenburg Gate is in Berlin at {{#geocode:Brandenburg Gate}}

Result: The Brandenburg Gate is in Berlin at 52° 30' 58.61" N, 13° 22' 39.73" E

Another common use case is to store coordinates in SMW using the coordinate data type, so they can be queried.

[[Has coordinates::{{#geocode: Brandenburg Gate}}]]

Parameters[edit | edit source]

Parameter Default Usage
location required The address you want to geocode.
format dms (changeable in wiki config with egMapsCoordinateNotation) The format to convert the coordinates to. See available coordinate formats
directional yes (changeable in wiki config with egMapsCoordinateDirectional) Indicates if the coordinates should be outputted directional or not. Must be either yes or no.

Examples[edit | edit source]

Basic syntax[edit | edit source]

{{#geocode:New York}}

Result: 40° 42' 45.82" N, 74° 0' 21.65" W

Specifying the output coordinate format[edit | edit source]

{{#geocode:location=New York City|format=float|directional=no}}

Result: 40.712728, -74.006015

{{#geocode:New York City|format=dms|directional=yes}}

Result: 40° 42' 45.82" N, 74° 0' 21.65" W

Passing along coordinates[edit | edit source]

This is to show that if you have a dynamic value that can be either an address or a set of coordinates, you can safely pass it to the #geocode parser function. If you want to convert coordinates into a different format, it is better to use the #coordinates parser function.

{{#geocode:40.7142691, -74.0059729}}

Result: 40° 42' 51.37" N, 74° 0' 21.50" W