2

Can anyone pls tell me what is the best way to find distance between two geopoints (lats, longs) in node.js . If there is any good node js library pls tell me. Also I dont want to find the straight line path i want to find the possible driving path between the locations.

Thank you in Advance

Sudhanshu Gaur
  • 7,486
  • 9
  • 47
  • 94

2 Answers2

10

You should try geopoint (https://www.npmjs.com/package/geopoint) In order to measure the distance from point1 to point2 use

`
var GeoPoint = require('geopoint');
point1 = new GeoPoint(lat1, long1);
point2 = new GeoPoint(lat2, long2);
var distance = point1.distanceTo(point2, true)//output in kilometers
`
Fotis Tsokos
  • 101
  • 1
  • 4
  • Actually I dont want to find the straight line path i want to find the possible driving path between the locations. Does it give shortest path or the possible path between the locations. – Sudhanshu Gaur Aug 02 '15 at 22:03
  • I 'm guessing shortest path. However through a quick search i found this module (https://www.npmjs.com/package/google-distance) which I believe may be what you're searching for, though I haven't yet tested it. – Fotis Tsokos Aug 02 '15 at 22:11
3

Ok, according to the wording of your last, you need a wrapper to services like Google Distance Matrix API or The Google Directions API. For example: Google Distance Matrix API for Node.js:

stdob--
  • 28,222
  • 5
  • 58
  • 73
  • Between google-distance-matrix and google-distance can you pls suggest which is better and why. – Sudhanshu Gaur Aug 02 '15 at 23:02
  • If you enough distance and time in transit, it is sufficient `Google Distance Matrix API`. For detailed information about the route including the transfer point, the different modes of transport and so on, you should use `Google Directions API`. – stdob-- Aug 02 '15 at 23:13
  • Last link is broken, any other suggestions where can I find Google Distance Matrix for Node JS? – Martín JF Feb 03 '22 at 16:01