0

I have pairs of gps coordinates (longitude latitude) and I would like to calculate the walking distance between them. i.e. using road data (from google maps or another open source) calculate the km of the shortest route between the two gps points. I could do it using google maps, but I have thousands of pairs so I would like to find a more automated way.

Does somebody know how to do it?

Stella
  • 1
  • 2
  • Please take a look at this post :- http://www.movable-type.co.uk/scripts/latlong.html – Bharat Nakum Oct 05 '16 at 12:50
  • And this can be more useful :- http://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-haversine-formula – Bharat Nakum Oct 05 '16 at 12:51
  • thank you @BharatNakum for your answer. unfortunately that is not what I was after. I have edited the question slightly in to clarify that. – Stella Oct 05 '16 at 16:48

1 Answers1

0

I am not quite sure about what you looking for. Just share some thoughts here:

1) If you want to calculate great circle distance between two points in lat/lon, you could use haversine formula distance. Example in JS:

function Haversine_distance(lat1,lon1,lat2,lon2) {
    var R = 6371; // in km
    var x1 = lat2 - lat1;
    var dLat = x1.toRad();
    var x2 = lon2 - lon1;
    var dLon = x2.toRad();
    var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
        Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
        Math.sin(dLon / 2) * Math.sin(dLon / 2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    var d = R * c;
    return d*1.0;
};

2) If you need more accurate distance calculation you need some correction factor, since earth is not a perfer sphere. It is always easier to project the locations you have to an appropriate projection and calculate distance there. For instance, project to UTM zones using proj4js, then calculate the distance to reduce the inaccuracy.

3) If you are talking about walking distance in cities, then it is network distance. It is required to have your road network build up first, then calculate from there. Without the road network, giving only point locations will not be enough to calculate the walking distance. Commercial data for road network is available from such as TeleAtlas. Free data can also be found via OpenStreetMap.

Teng Ma
  • 353
  • 2
  • 9
  • thank you for your reply. unfortunately this in not was I was after. I have tried to clarify the question. – Stella Oct 05 '16 at 16:41
  • Quit unfortunate i did not get your idea. If you can do it via google manually and you are looking for some existing work/tool that do the same thing, i am sorry i dont have the quick answer to that. But if you can do some coding, it is good to take a look at google api documentation for this https://developers.google.com/maps/documentation/distance-matrix/intro – Teng Ma Oct 05 '16 at 20:34
  • And google map is using TeleAtlas road network data that i mentioned, it is not 'free'. Please read the term before using it with your key. – Teng Ma Oct 05 '16 at 20:36