This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Setting the initial To-address in …/directions/ by passing a parameter via URL

0

I would like to know how I can call https://www.openstreetmap.org/directions/ with a parameter so that the field To: is filled with a value. Is this possible?

asked 03 Apr '20, 12:55

normannescio's gravatar image

normannescio
26223
accept rate: 0%


One Answer:

5

Sure, it's easy, just add ?to=[your destination] to the end of the URL.

Example: https://www.openstreetmap.org/directions?to=London

Note:

  • The destination string is interpreted (by Nominatum I think) so what appears in the "To" box might not be an exact match. In this case "London" becomes "London, Greater London, England, SW1A 2DX, United Kingdom"
  • You can add more detail to the destination but you may have to URL-encode some characters, eg https://www.openstreetmap.org/directions?to=London%2C%20Ontario becomes "London, Ontario" which is interpreted as "London, Southwestern Ontario, Ontario, N6A 1G4, Canada."
  • You can also use coordinates as the destination -- but OSM will still attempt to guess an address, which sometimes succeeds and sometimes doesn't, eg https://www.openstreetmap.org/directions?to=51.4918%2C-0.1588
  • If the user has visited openstreetmap.org before, the map will not automatically center on the destination. It will show wherever the user last was looking at OSM. If you want to control the map center and zoom, you can do so with additional URL parameters like this: https://www.openstreetmap.org/directions?to=London#map=10/51.4818/-0.1414 (here, 10 is the zoom level, 51.4818 is the latitude, and -0.1414 is the longitude.)

answered 04 Apr '20, 17:34

jmapb's gravatar image

jmapb
3.4k73361
accept rate: 22%

edited 05 Apr '20, 04:04

Thanks, works like a charm.

(06 Apr '20, 08:03) normannescio

Source code available on GitHub .