2

I am working on a javascript application where I need to find the nearest line from a point. Every point is expressed in geo format (latitude and longitude). So I want to calculate the minimum distance of point to every line and compare that to find the nearest line.

The problem is how do I find the nearest distance to a line of a point in geo format? There are some methods given for x-y coordinate system but I don't know how to use them in geo coding format.

Can someone give me some pointers as how to do it? Though I am looking for javascript solution but even language-agnostic approach is fine.

Naman
  • 2,569
  • 4
  • 27
  • 44
  • It sounds like you want to compute distances between entities that exist in different worlds: how do you represent the lines using geo coordinates? I'm not aware of a method for doing this. Maybe convert your points to cartesian coordinates, and then worry about finding the closest line. – IVlad Feb 14 '15 at 22:47
  • @IVlad Actually the line is represented as its start and end point expressed in latitude-longitude format. I am sorry but I don't understand why is this invalid format to represent line on map? – Naman Feb 14 '15 at 22:54
  • Ok, maybe that is easier then. I thought you meant a straight line, sorry. – IVlad Feb 14 '15 at 23:05
  • No I didn't mean that, sorry for the confusion. Can you please provide the answer? – Naman Feb 14 '15 at 23:07
  • 1
    I'll think about it, but I don't have one at the moment. My initial thought was to convert geo -> cartesian and go from there, but that's off the table now. – IVlad Feb 14 '15 at 23:09
  • 1
    Surprising, it appears this has already been asked before: [How to calculate distance from a point to a line segment, on a sphere?](http://stackoverflow.com/questions/1299567/how-to-calculate-distance-from-a-point-to-a-line-segment-on-a-sphere) Please let me know if this is not what you want. – Qantas 94 Heavy Feb 15 '15 at 00:05
  • Thanks a lot, it does seem exactly like what I want. I will give it a try and let you know if it works. – Naman Feb 15 '15 at 00:51
  • @Naman, have you got any answer for this question? I am having same problem and not able to find the solution. Can you please post your solution here? Thanks. – meen Nov 03 '16 at 14:13

0 Answers0