1

how to calculate a distance between two locations?

asked 19 Jan '13, 16:06

Marco%20Schumann's gravatar image

Marco Schumann
16112
accept rate: 0%

2

A bit more information about what you're trying to do here would help.

Do you want the great circle distance between two locations on the earth's surface, or the travel distance from one to another calculated by a router for a particular mode of transport?

(20 Jan '13, 13:54) SomeoneElse ♦

3 Answers:
3

This is not an OpenStreetMap specific question.

In software, a formula called the Haversine formula is used to compute the distance between two points. You will likely find example implementations in your programming language of choice if you search for them on the web.

permanent link

answered 19 Jan '13, 16:48

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
73.3k866641137
accept rate: 24%

2

You can use a router e.g. an online one like yournavigation or OSRM, of course these can only be used for small amount of lookups (see OSRM api policy), and they candisapear at any moment. If you want to lookup lots of these distances you will have to install something of your own, installing Gosmore is quite easy, OSRM I've never tried to install.

These are the URLs to use.

http://yournavigation.org/api/dev/route.php?flat=59.31934&flon=18.0572&tlat=58.4162&tlon=15.5523&v=motorcar&fast=1&instructions=1
http://router.project-osrm.org/viaroute?z=6&loc=59.3193,18.0572&loc=58.4162,15.5523&alt=false

it's very simple to extract the distance from these results.

 OSRM: "route_summary":{"total_distance":199988
YOURS:  <kml><Document><distance>200.510334</distance>

See OSRM server API for more info

permanent link

answered 24 Jan '13, 11:47

emj's gravatar image

emj
2.0k123447
accept rate: 15%

edited 19 Jun '13, 12:33

0

If you need to calculate a distance often some mapping software will help. I have recently installed an OSM map into Garmin's Basecamp and Mapsource both, or either can be downloaded free. They are very similar and I'm not sure why both exist or which is best. They're good and are great for route planning and sending maps,way points and routes (plotted or auto routing) to my Garmins along roads or paths.

permanent link

answered 22 Jan '13, 10:14

andy%20mackey's gravatar image

andy mackey
12.0k76128263
accept rate: 4%

sorry mapsource may not work without a garmin device but basecamp will, I think, http://www8.garmin.com/support/download_details.jsp?id=4435

(22 Jan '13, 10:24) andy mackey

wiki.openstreetmap.org/wiki/BaseCamp

(22 Jan '13, 10:28) andy mackey

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:

×51

question asked: 19 Jan '13, 16:06

question was seen: 8,801 times

last updated: 19 Jun '13, 12:33

powered by OSQA