Make writing a habit together! This is my first day to participate in the “Gold Digging Day New Plan · April More text challenge”, click to see the details of the activity.

Latitude and longitude interchange

Degree (DDD) : E 108.90593 degree N 34.21630 degree

How to convert DDD: : 108.90593 degrees into DMS E 108 degrees 54 minutes 22.2 seconds? The conversion method is to change the integer bit of 108.90593 to 108(degrees), 0.9059360=54.3558, take the integer bit of 54(minutes),0.355860=21.348 and then take the integer bit of 21(seconds), so it is converted to 108 degrees 54 minutes and 21 seconds.

The DMS (east longitude E 108 degrees 54 minutes 22.2 seconds) is converted into DDD as follows :108 degrees 54 minutes 22.2 seconds =108+(54/60)+(22.2/3600)=108.90616 degrees

Because of the reservation of decimal place, there is some error in positive and negative calculation, but the influence of error is not very big. An error of one second is the appearance of a few meters. GPS car users can use the above method to convert into their own unit coordinates.

The latitude and longitude are converted into meters

Latitude is divided into 60 minutes, and each minute is subdivided into 60 seconds and fractions of seconds. Latitude lines projected on the diagram look like horizontal parallel lines, but are actually circles of different radii. All positions with the same specific latitude are on the same latitude line. The equator has a latitude of 0°, bisecting the planet into the northern and southern hemispheres. Latitude is the line Angle between a point and the earth’s center and the earth’s equatorial plane. It is between 0 and 90 degrees. The latitudes of the points north of the equator are called N, and the latitudes of the points south of the equator are called S. Regions with latitude values between 0 and 30 degrees are called low latitudes, those between 30 and 60 degrees are called middle latitudes, and those between 60 and 90 degrees are called high latitudes. The equator, tropic of Cancer, Tropic of Cancer, Antarctic circle and Arctic Circle are special parallels of latitude. The total length of the earth’s meridians is about 40008km. Average: latitude 1 degree = approximately 111km latitude 1 minute = approximately 1.85km latitude 1 second = approximately 30.9m

Calculate the distance between any two points on the earth based on their latitude and longitude

The Earth is a near-standard ellipsoid with an equatorial radius of 6378.140 km, a polar radius of 6356.755 km, and an average radius of 6371.004 km. If we assume that the Earth is a perfect sphere, then its radius is the average radius of the Earth, denoted R. If 0 degree longitude is taken as the base, then the surface distance between any two points on the earth surface can be calculated according to the latitude and longitude of the two points (here, the error caused by the calculation of the earth surface topography is ignored, so it is only a theoretical estimate). Let the Longitude and Latitude of the first point A be LonA, LatA, and the Longitude and Latitude of the second point B be LonB, LatB. According to the Longitude of 0 degrees, the Longitude Longitude Longitude is positive Longitude Longitude, the Longitude Longitude is negative Longitude Longitude and the Latitude of the second point B is 90-latitude. If the southern Latitude is 90+Latitude, the two points after the above treatment are calculated as (MLonA, MLatA) and (MLonB, MLatB). According to trigonometric derivation, the following formula can be obtained to calculate the distance between two points:

C = sin(MLatA)*sin(MLatB)*cos(MLonA-MLonB) + cos(MLatA)*cos(MLatB)

Distance = R*Arccos(C)*Pi/180

Here, R and Distance are in the same unit. If 6371.004 km is used as the radius, then Distance is in the unit of kilometers. If other units, such as mile, are used, unit conversion is needed, 1 km =0.621371192mile

If only the longitude is treated as positive and negative, and the Latitude is not treated as 90-latitude (assuming both are in the Northern hemisphere and only Australia in the southern hemisphere has application significance), then the formula will be:

C = sin(LatA)*sin(LatB) + cos(LatA)*cos(LatB)*cos(MLonA-MLonB)

Distance = R*Arccos(C)*Pi/180

So this is just a simple trig.

If both the input and output of the trigonometric function take radians, the formula could also be written:

C = sin(LatAPi/180)sin(LatBPi/180) + cos(LatAPi/180)cos(LatBPi/180)*cos((MLonA-MLonB)*Pi/180)

Distance = R*Arccos(C)*Pi/180

That is:

C = sin(LatA/57.2958)*sin(LatB/57.2958) + cos(LatB/57.2958)*cos((mlona-mlonb)/57.2958)

Short = RArccos Arccos (C) = 6371.004 (C) kilometer = 0.6213711926371.004 Arccos (C) the mile = 3958.758349716768 * Arccos (C) mile

According to a latitude and longitude, calculate the radius of the current latitude and longitude, can be used to punch, occasions. Utility class

/** * latitude and longitude, fence related tools * according to a latitude and longitude, calculate the radius of the current latitude and longitude, can be used to punch, occasions. * @author zhangtonghao * @create 2022-03-17 14:37 */ public class FenceUtils {// PI private static final double PI = 3.1415926; /** * Calculate the distance between any two points on earth ** @param long1 first point longitude * @param lat1 first point latitude * @param long2 second point longitude * @param lat2 second point latitude * @return Return distance unit: M */ public static int distancebylongat (double long1, double long2, double lat2) {double a, b, R; // Earth radius R = 6378137; Lat1 = lat1 * math.pi / 180.0; Lat2 = lat2 * math.pi / 180.0; a = lat1 - lat2; B = (long1-long2) * math.pi / 180.0; double d; double sa2, sb2; Sa2 = math. sin(a / 2.0); Sb2 = math. sin(b / 2.0); d = 2 * R * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1) * Math.cos(lat2) * sb2 * sb2)); return (int)d; } /** * Calculate latitude and longitude range based on latitude and longitude and radius ** @param raidus unit meter * @return minLat, minLng, maxLat, maxLng */ public static double[] getAround(double lat, double lon, int raidus) { Double latitude = lat; Double longitude = lon; Double degree = (24901 * 1609) / 360.0; double raidusMile = raidus; Double dpmLat = 1 / degree; Double radiusLat = dpmLat * raidusMile; Double minLat = latitude - radiusLat; Double maxLat = latitude + radiusLat; Double mpdLng = degree * Math.cos(latitude * (PI / 180)); Double dpmLng = 1 / mpdLng; Double radiusLng = dpmLng * raidusMile; Double minLng = longitude - radiusLng; Double maxLng = longitude + radiusLng; return new double[]{minLat, minLng, maxLat, maxLng}; }}Copy the code

Test use:

If this article is useful to you, please click blue!