↑ OpenStreetmap Hacker's guide ↑↑ Net & Web  

The OpenStreetmap web map

Locations -- Routes -- Objects

The most well-known part of OpenStreetmap is certainly its map web app, so before we start on the hackery, here is an overview of what you can do with it and how you can construct URLs for its features. That allows you to generate such URLs automatically, for example to link to a varying location from a script on your own website.

Locations

The most basic map URL describing a specific location and region of the map has the following form:

http://www.openstreetmap.org/#map=<zoom>/<latitude>/<longitude>

The latitude and longitude refer to the location of the centre of the map, the zoom level gives its scale. In zoom level 13, the scale is ≈ 13 metres per pixel. Larger zoom values give a more accurate scale, and successive zoom levels differ by a factor 2.

Something to bear in mind when sending hyperlinks to OpenStreetmap web maps around ist that the size of the map section cannot be fixed, but will depend on the size of the browser window in which they are viewed.

Further features are enabled by parameters in the URL. Some of these have to be put before, some after the map location. A parameter after the location can for example be used to select a "map layer" (map appearance). The following example selects the OpenCycleMap syle:

http://www.openstreetmap.org/#map=12/46.9008/10.4885&layers=C

The following map styles are available:

Style URL suffix
Standard (none)
Cycle Map &layers=C
Transport Map &layers=T
Mapquest Open &layers=Q
Humanitarian &layers=H

A marker can be put into the map by appending parameters before the map location:

http://www.openstreetmap.org/?mlat=45.9244&mlon=8.5620#map=14/45.9336/8.5635
http://www.openstreetmap.org/?mlat=45.9244&mlon=8.5620

When the map location part is omitted, the map will be displayed at the marker location at zoom level 12, ≈ 26 metres / pixel. Unless you have a machine-readable source of locations, you have to copy the marker location from the map location you adjusted interactively. For a different way of marking buildings and streets, see under Objects below.

Routes

OpenStreetmap's routing app is accessed via the base URL http://www.openstreetmap.org/directions. When specifying place names for OpenStreetmap to resolve, the parameters from and to are used, as in this example:

http://www.openstreetmap.org/directions?from=frankfurt&to=berlin

More complex locations such as addresses can be given instead of place names, they only have to be URL encoded.

If one or both endpoints of the route are not place names in the OpenStreetmap database (such an arbitrary point on a highway), the geocoordinates of both endpoints have to be given explicitly. This is the format into which the routing URL is converted automatically after looking up place names. It uses a single parameter route which contains both endpoints in the format <start latitude>,<start longitude>;<destination latitude>,<destination longitude>. The separating commas and semicolon have to be URL encoded. An example:

http://www.openstreetmap.org/directions?route=46.390%2C14.084%3B46.411%2C13.996

OpenStreetmap offers multiple routing engines. They are selected with the engine parameter, and the choices are:

Routing engine Value of engine parameter
Car (OSRM) (default) osrm_car
Car (Mapzen) mapzen_car
Bicycle (Mapzen) mapzen_bicycle
Bicycle (GraphHopper) graphhopper_bicycle
Foot (Mapzen) mapzen_foot
Foot (GraphHopper) graphhopper_foot

The routing for the different modes of transport differs in the time computation and the available roads, and different algorithms for the same mode of transport sometimes prefer different routes.

All routing URL parameters have to precede a map location fragment, when present.

Objects

OpenStreetmap also allows to mark map objects in the online map. As will be explained on the contribution page, OpenStreetmap map data consists of nodes (points) and paths (polylines between points, possibly closed). Buildings are represented by closed paths, and if you search for an address, they are marked in the map view, resulting in a URL of the following form:

http://www.openstreetmap.org/way/30419789

Streets are open paths and can also be found by the web map search:

http://www.openstreetmap.org/way/25008527

If you are used to editing OpenStreetmap data, you can also mark ordinary points that cannot be found by their metadata, such as an arbitrary point on a road:

http://www.openstreetmap.org/node/2324617496

One should note that these IDs are not permanent, but may change if someone edits the map data. But for good quality map regions, that is not likely to happen frequently.


Licensed under the Creative Commons Attribution-Share Alike 4.0 Germany License

TOS / Impressum