ios-map True coordinate representation between representations (double type, int type reciprocal transition)

Source: Internet
Author: User
Tags cos in degrees sin

You may encounter this requirement in development, the geographic coordinates obtained by the front end cannot be represented as double in the background, and need to be converted to other styles such as: xx-xx-xx-second form representation and then into the form of second-shaping

Encapsulates two classes to directly achieve the map latitude and longitude coordinates real and shaping the way the representation method is converted:

/** How to Degree (DDD):: 108.90593 degrees conversion into degrees seconds (DMS) Longitude e 108 degrees 54 minutes 22.2 seconds? The conversion method is to change the 108.90593 integer digits to 108 (degrees), use 0.90593*60=54.3558, take the integer digit 54 ( ), 0.3558*60=21.348 and then take the whole digit 21 (seconds), so converted to 108 degrees 54 minutes 21 seconds. The same will be the degree of seconds (DMS): East longitude e 108 degrees 54 minutes 22.2 seconds conversion into degrees (DDD) method is as follows: 108 degrees 54 minutes 22.2 seconds =108+ (54/60) + (22.2/3600) =108.90616 degrees because of the reason for the number of decimal digits to be calculated, There is a certain error in positive and negative calculation, but the error effect is not very large. The 1-second error is a few meters. GPS car Friends can use the above method to convert to their own desired unit coordinates. *//** * Incoming map coordinates get the server storage degrees * * @param degree coordinates */+ (Nsinteger) Secondfromdegree: (cgfloat) degree{Nsinteger degreetemp,minutetemp,secondtemp;    CGFloat temp;    Degreetemp = (nsinteger) degree; temp = (cgfloat) (degree-degreetemp) * -;    Minutetemp = (nsinteger) temp; Secondtemp = (Nsinteger) ((temp-minutetemp) * -);returnDegreetemp *3600+ minutetemp * -+ +;}/** * Incoming server storage in degrees get map coordinates * * @param Second server degrees */+ (CGFloat) Degreefromsecond: (nsinteger) second{Nsinteger degreetemp,minutetemp,secondtemp; Degreetemp = (Nsinteger) Second/3600; Minutetemp = (Nsinteger) Second%3600/ -; Secondtemp = (Nsinteger) Second%3600% -;return(CGFloat) (Degreetemp + (Minutetemp/60.0) + (Secondtemp/3600.0));}

Interchange by latitude
Degrees (DDD): E 108.90593 degrees N 34.2163 degrees
How to convert degrees (DDD):: 108.90593 degrees to degrees seconds (DMS) Longitude e 108 degrees 54 minutes 22.2 seconds? The conversion method is to change the 108.90593 integer digits to 108 (degrees), use 0.90593*60=54.3558, take integer digits 54 (min), The 0.3558*60=21.348 is then rounded to 21 (seconds), which translates to 108 degrees 54 minutes and 21 seconds.
The same will be the degree of seconds (DMS): East longitude e 108 degrees 54 minutes 22.2 seconds conversion into degrees (DDD) method is as follows: 108 degrees 54 minutes 22.2 seconds =108+ (54/60) + (22.2/3600) = 108.90616 degrees
Because of the reason that the decimal digit is retained in the calculation, there is a certain error in the positive and negative calculation, but the error effect is not great. The 1-second error is a few meters. GPS car Friends can use the above method to convert to their own desired unit coordinates.

Converted to meters by latitude
Latitude is divided into 60 points, each divided into 60 seconds and fractional seconds.

The latitude line projects seemingly horizontal parallel lines on the graph, but is actually a circle of different radii. All locations with the same specific latitude are on the same parallel.
The equatorial latitude is 0°, dividing the planets into the southern and northern hemispheres.
Latitude refers to the line angle between a point and the Earth's spherical surface and the equatorial plane of the earth, and its value is between 0-90 degrees. The latitude of the point north of the equator is called Latitude, which is recorded as N, and the latitude of the point south of the equator is said to be S.
Latitude values in the region between 0-30 degrees called the low latitude region, the latitude value in the area between 30-60 degrees is called the middle latitude region, the latitude value in the area between 60-90 degrees is called the high latitude region.
The equator, the southern Tropic, the Tropic of Cancer, the Antarctic Circle and the Arctic Circle are special parallels.
Latitude 1 seconds in length
The total meridian length of the earth is about 40008km. Average:
Latitude 1 degrees = approximately 111km
Latitude 1 min = approximately 1.85km
Latitude 1 sec = approximately 30.9m
Calculates the distance between two points according to the latitude and longitude of any two points on the Earth (can be c=a2+b2 with Pythagorean theorem)
The earth is a nearly 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, recorded as R. If the 0-degree meridian is used as a benchmark, the surface distance between the two points can be calculated based on the latitude and longitude of any two points on the Earth's surface (this ignores the error caused by the Earth's surface topography, which is only a theoretical estimate). The latitude and longitude of 1th A is (Lona, LatA), the latitude and longitude of 2nd B is (LONB, LATB), according to the datum of 0 degrees longitude, the positive value of longitude (longitude), the longitude is negative (-longitude), north latitude takes 90-latitude value (90- Latitude), 90+ latitude value (90+latitude), the two points after the above treatment are counted as (Mlona, Mlata) and (Mlonb, MLATB). Then, according to triangular derivation, we can get the following formula to calculate the distance of two points:
C = sin (mlata) *sin (MLATB) *cos (mlona-mlonb) + cos (mlata) *cos (MLATB)
Distance = R*arccos (C) *pi/180
Here, R and distance units are the same, if the use of 6371.004 km as a radius, then distance is the unit, if you want to use other units, such as mile, also need to do unit conversion, 1-kilometer =0.621371192mile
If the longitude is treated only as positive or negative, and the latitude is not 90-latitude (assuming that the northern hemisphere is the only application in the southern hemisphere), then the formula will be:

sin(LatA)*sincos(LatA)*cos(LatB)*cos(MLonA-MLonB)Distance = R*Arccos(C)*Pi/180

The above can be introduced through a simple triangular transformation.
If the input and output of trigonometric functions are in radians, then the formula can also be written:

sin(LatA*Pi/180)*sin(LatB*Pi/180cos(LatA*Pi/180)*cos(LatB*Pi/180)*cos((MLonA-MLonB)*Pi/180)Distance = R*Arccos(C)*Pi/180

That is

c = sin  (Lata/57.2958 ) *sin  (Latb/57.2958 ) + cos  (Lata/57.2958 ) *cos  (Latb/57.2958 ) *cos  (mlona-mlonb)/57.2958 ) Distance = R*arccos  (c) = 6371.004  *arccos  (c) kilometer = Span class= "Hljs-number" >0 . 621371192  *6371 . 004  *arccos  (c) mile = 3958.758349716768  *arccos  (c) mile 

In practical application, it is generally through an individual zip code to find the corresponding regional center of latitude and longitude, and then based on these latitude and longitude to calculate the distance between each other, so as to estimate the approximate distance between certain groups of the range ( For example, the distribution of hotel passengers-the latitude and longitude of each traveler's postal code and the distance range computed by the latitude and longitude of the hotel-and so on, so a database is a useful resource for querying latitude and longitude by postal code.

ios-map True coordinate representation between representations (double type, int type reciprocal transition)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.