NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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%


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.)
permanent link

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

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×39
×4

question asked: 03 Apr '20, 12:55

question was seen: 2,440 times

last updated: 06 Apr '20, 09:31

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum