Home computickets How to find the distance between two points on the maps?

How to find the distance between two points on the maps?

Author

Date

Category

only their latitude and longitude are known. Distance Find you need in meters.


Answer 1, Authority 100%

(a great example of Bullshit in other answers)

Example of using Haverersine Formula on javascript you can find here.

The calculation on specialized formulas makes sense to produce only at large distances. In addition, if such a calculation is needed – it is necessary to determine which type of line is a line of equal delets or a large circle, and which date and geoid will be used (usually use WGS84).

For the simplest calculations within a few kilometers, spherical formula is quite acceptable.


ANSWER 2, AUTHORITY 11%

Static Final Double Earth_radius = 6371009; // Land radius in m
 / **
 * Returns Distance on the Unit Sphere; The Arguments Are in Radians.
 * /
Private Static Double Distanceradians (Double Lat1, Double Lng1, Double Lat2, Double LNG2) {
  RETURN ARCHAV (HAVDISTANCE (LAT1, LAT2, LNG1 - LNG2));
}
/ **
* Returns The Length of the Given Path, In Meters, On Earth.
 * /
Public Static Double ComputeLength (List & LT; Latlng & GT; Path) {
  if (patch.size () & lt; 2) {
    Return 0;
  }
  Double Length = 0;
  Latlng prev = path.get (0);
  Double Prevlat = Toradians (prev.latitude);
  Double Prevlng = Toradians (Prev.longitude);
  For (Latlng Point: Path) {
    Double Lat = Toradians (point.latitude);
    Double LNG = Toradians (Point.longitude);
    Length + = Distanceradians (Prevlat, Prevlng, Lat, LNG);
    prevlat = lat;
    prevLNG = LNG;
  }
  Return Length * Earth_radius;
}

Stero from Android Maps Utils

How to use?

// list of points for comparison distance
ArrayList & LT; Latlng & GT; Latlnglist = new arraylist & lt; latlng & gt; ();
Latlnglist.add (new latlng (latitude1, longitude1));
Latlnglist.add (new latlng (latitude2, longitude2));
Double Plength = SPHERICALUTIL.COMPuteLength (LatlnGlist);

In the variable Plength there will be a distance in meters


Answer 3

You need to apply Pythagore theorem. The difference in latitude is one or triangle catt, the difference in longitude is the other, and the hypotenuse is just the desired distance between the points.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions