I am working on an application with Spatial data. Here I need to find the distance from the centroid to a point. Can know how to convert miles to degrees in Java?
-
3At what latitude? On earth? – Bohemian Jan 15 '13 at 18:21
-
Yes. I need to know how to convert miles to degrees in Java. – Rakesh Gourineni Jan 15 '13 at 18:22
-
1You might find an algorithm on the GIS site that you could implement in java - http://gis.stackexchange.com/ – Dan W Jan 15 '13 at 18:27
-
1If you're trying to find the distance (in miles?) between two centroids which are expressed in lat/lon, then you're actually looking for formulae to calculate the distance between two lat/lon positions, aren't you? – Zoltán Jan 15 '13 at 18:30
-
@Zoltan, I am looking for formula to convert miles to degrees (in Java).. – Rakesh Gourineni Jan 15 '13 at 19:04
4 Answers
Final Edit: Look into Great Circle Distance and Geodesics to discover the complexities of what you were really asking in this question. This is admittedly well out of my familiarity with mathematics.
[Leaving original suggestions in for historical reasons. Though pieces may help you, they will not directly answer your question.]
See https://stackoverflow.com/a/1253545/1964221 for the answer to this question.
Latitude: 1 deg = 110.54 km
Longitude: 1 deg = 111.320*cos(latitude) km
To go the other direction, I wonder if we can do this(my algebra is rusty):
Latitude: 1 km = 1 deg / 110.54 km
Longitude: 1 km = 1 deg / (111.320*cos(latitude) km)
Application
Is your distance always strictly East-West or North-South? If so, you should be able to say:
Integer latTraveledMiles = 100;
Double latTraveledKM = 100 * 0.621371;
Double latTraveledDeg = (1 / 110.54) * latTraveledKM;
or
Double currentLat = 74.0064;
Integer longTraveledMiles = 100;
Double longTraveledKM = 100 * 0.621371;
Double longTraveledDeg = (1 / (111.320 * Math.cos(currentLat))) * longTraveledKM;
More than likely, you will need to know distance in both North-South and East-West directions(and takes this into the realm of "not straight-forward). You could look at the Pythagorean Theorem. You know the "long side" of the triangle(c^2) and can calculate for longitude(a^2) and latitude(b^2).
You should be able to apply portions of my previous code snippets to figure out
c = sqrt(a^2 + b^2).
Good luck.

- 1
- 1

- 600
- 3
- 9
If this is really a straight forward question we should ignore latitude and longitude, and just look at the angle between the radii to two points such that the distance between them, along the great circle containing both points, is m miles.
To keep it really straight forward, we should assume the earth is spherical, so that the answer is independent of location. I'm using mean radius 3,958.761 miles.
One radian is the angle for a line 3,958.761 miles long, so the angle for a line m miles long is m/3,958.761 radians. Use Math.toDegrees if you want the angle in degrees.

- 25,849
- 4
- 38
- 75
-
1with the information given, treating this as an abstract spherical angle rather than a lat/long problem seems the only approach. – Alnitak Jan 15 '13 at 19:26
Expressing your distance in degrees is an incorrect approach because the distance degrees represent is not equal in all positions on the earth and they are expressed differently for latitude and longitude.
Examples: 1° longitude on the equator is about 70 miles, whereas around the north pole it's a few feet.
Latitude does not change over the surface of the earth, but what about distances which are not along a meridian or a parallel? Which measure would you represent those in?

- 21,321
- 14
- 93
- 134
-
Thanks for the reply Zoltan. Do we have any algorithm for that conversion. miles to degrees. – Rakesh Gourineni Jan 15 '13 at 18:25
-
@RakeshGourineni I think you need to further define the problem. In particular, what result do you want if the line between the two points is not along a meridian or a parallel. That affects your result. – Patricia Shanahan Jan 15 '13 at 18:42
-
I think my question is straight forward. Convert miles to degrees. – Rakesh Gourineni Jan 15 '13 at 18:45
-
5@RakeshGourineni no, your question is not even remotely straight forward. – Alnitak Jan 15 '13 at 19:25
-
1Agree, that question makes as much sense as how to convert miles to US dollars. – user1702401 Jan 16 '13 at 22:38
Answer by dwight-degroff is great (thanks, it helped me), but contains one mistype, which of course is of very low importance. If you want to be more correct (e.g. you're preparing tests based on external data coming from source with many decimal places), then it should be
Latitude: 1 km = 1 deg / 110.574 km
instead of:
Latitude: 1 km = 1 deg / 110.54 km
And thus for latitude it is:
Integer latTraveledMiles = 100;
Double latTraveledKM = 100 * 0.621371;
Double latTraveledDeg = (1 / 110.574) * latTraveledKM;
And actually, for longitude it's 111.319 instead of 111.320, so:
Double currentLat = 74.0064;
Integer longTraveledMiles = 100;
Double longTraveledKM = 100 * 0.621371;
Double longTraveledDeg = (1 / (111.319 * Math.cos(currentLat))) * longTraveledKM;
However, both corrections might be negligible.

- 86
- 7