Distance calculation between two latitude and longitude degrees

Source: Internet
Author: User
Tags constant definition

Here is the code to calculate the distance between the two latitude and longitude, divided into: header file, source code and test code three parts.
Specific as follows:

1 //LatLonDistanceDlg.h: Header file2 //  3   4 #pragmaOnce5   6typedefstruct  7 {  8     DoubleDlongitude; 9     DoubleDlatitude; Ten}mylatlong_t,*pmylatlong_t;  One    A //Clatlondistancedlg dialog Box - classClatlondistancedlg: PublicCDialog - {   the     ......   -    -     voidDistanceoftwopositions (mylatlong_t Ll_posstart, mylatlong_t ll_posend,Double&dis);  - //Implement + protected:   -     ......   + };  A    at //LatLonDistanceDlg.cpp: Implementing Files - //   -    - //constant Definition - Const DoubleGCONSTPI =3.1415926536;  - //WGS-84 Long shaft radius in #defineEARTH_LONG_RADIUS_WGS84 6378137.0//Unit: M - //WGS-84 Earth Flat rate (terrestrial flattening) to #defineEARTH_FLATTENING_WGS84 298.257223563 + //meters per sea mile - #defineMeters_per_sea_mile 1852.0 the    * //input parameters: mylatlong_t is a structure, including longitude and latitude $ //output parameter: Ddistance is the return circle distancePanax Notoginseng voidClatlondistancedlg::D istanceoftwopositions (mylatlong_t startlatlong, mylatlong_t Endlatlong,Double&ddistance) - {   the     DoubleDinradians;  +     DoubleDtmpval =0.0;  A     DoubleDFi =0.0;  the     DoubleDFi2 =0.0;  +     DoubleDdrda = Endlatlong.dlongitude-Startlatlong.dlongitude;  -     DoubledTMP =0.0;  $     DoubleDTMP2 =0.0;  $    -Ddrda = Ddrda * GCONSTPI/180.0;//In radians -DFi =Startlatlong.dlatitude;  theDFi2 =Endlatlong.dlatitude;  -   WuyiDFi = DFi * GCONSTPI/180.0;//In radians theDFi2 = DFi2 * GCONSTPI/180.0;//In radians -    WuDtmpval = sin (dFi) * sin (dFi2) + cos (dFi) * cos (DFI2) *cos (DDRDA);  -     if(Fabs (Dtmpval) >1.0)   About     {   $AfxMessageBox (L"Invalidate value of arccos!");//Use Unicode Character Set -         return ;  -     }   -Dinradians = ACOs (dtmpval);//In radians AdTMP = (sin (dFi) +sin (dFi2));  +DTMP2 = (sin (dFi)-sin (dFi2));  theDtmpval = ((3* SIN (Dinradians)-Dinradians) * dtmp * dtmp)/(1+cos (dinradians));  -Dtmpval = Dtmpval-((3* SIN (Dinradians) + dinradians) * DTMP2 * dTmp2)/(1-cos (dinradians));  $    theddistance = earth_long_radius_wgs84 * Dinradians + (EARTH_LONG_RADIUS_WGS84/(4* earth_flattening_wgs84)) * DTMPVAL;//In meters the }   the    the //Test Code - //TODO: Add additional initialization code here in {   the     //Shenzhen Lily Hotel Latitude: 22.601369, longitude 114.115145 the     //Shenzhen Lily Star City Latitude: 22.601334, longitude 114.115807 About     //shenzhen Bouginon Batch latitude: 22.583596, longitude 114.112227 the mylatlong_t LatLon;  the mylatlong_t LatLon2;  the mylatlong_t LatLon3;  +     DoubleDDIs =0.0;  -    theLatlon.dlatitude =22.601369; BayiLatlon.dlongitude =114.115145;  theLatlon2.dlatitude =22.601334;  theLatlon2.dlongitude =114.115807;  -Latlon3.dlatitude =22.583596;  -Latlon3.dlongitude =114.112227;  the    the distanceoftwopositions (Latlon,latlon2,ddis);  theTRACE ("%f\r\n", DDIs);//68.177865 the distanceoftwopositions (Latlon,latlon3,ddis);  -TRACE ("%f\r\n", DDIs);//1990.891295 the}

Distance calculation between two latitude and longitude degrees

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.