## 2 Materials and Methods
### Determination of the Cardinal Direction  
Smartphones use a combination of the azimuth, pitch, and roll to calculate cardinal directions. However, this combination has the disadvantage of being excessively sensitive, as the azimuth constantly changes due to slight shaking even though the smartphone is moving in a certain direction. In addition, the azimuth sensor also has a distortion phenomenon according to surrounding structures and geomagnetic distribution, and measures the most accurate value when parallel to the ground. The main causes are the influence of the surrounding metal structures and the tilt of the azimuth. However, as the user is not always horizontal when the user holds the smartphone, distortion occurs due to the inclination of the smartphone [29, 30]. Therefore, the determination of the direction angle using the azimuth sensor is unsuitable for determining the geographic or topological sequence of connected cars. However, orientation determination using only latitude and longitude can yield a very accurate directional state. Thus, this paper proposes Algorithm 1 (derived from Table 1) to determine the cardinal direction using topological differences in latitude and longitude. Table 1 lists two factors for determining the cardinal direction, and the cardinal directions in eight cases. The differences in latitudes and longitudes follow Equations (1) and (2). \[\text{difference}\text{Latitude}=\text{current}\text{Latitude}-\text{before} \text{Latitude} \tag{1}\]  
\[\text{difference}\text{Longitude}=\text{current}\text{Longitude}-\text{before} \text{Longitude} \tag{2}\]  
In Equation (1), \(\text{difference}\text{Latitude}\) is the difference between \(\text{current}\text{Latitude}\) (latitude value of the current location) and \(\text{before}\text{Latitude}\) (latitude of the before location), and Equation (2) follows the same principle. The cardinal direction is also determined by whether the difference is positive or negative in the eight cases. Taking case 5 in Table 1 as an example, if a vehicle moves in the northeast direction, both latitude and longitude increase, so if the differences in latitude and longitude are positive, the cardinal direction is identified as northeast. Algorithm 1 indicates this process. ```
/* Input: currentLatitude, currentLongitude, beforeLatitude, beforeLongitude */ BEGIN IF beforeLatitude=0 and beforeLongitude=0 THENRETURN terminate ENDIF differenceLatitude=currentLatitude-beforeLatitude differenceLongitude=currentLongitude-beforeLongitude IF differenceLatitude=0 anddifferenceLongitude=0 THEN heading=the azimuth angle by sensor ELSE heading=updateDirection(differenceLatitude, differenceLongitude) ENDIF differenceLatitude>0 anddifferenceLongitude=0 THENheading=N ELSEIF differenceLatitude<0 anddifferenceLongitude=0 THENheading=S ELSEIF differenceLatitude=0 anddifferenceLongitude>0 THENheading=E ELSEIF differenceLatitude=0 anddifferenceLongitude<0 THENheading=W ELSEIF differenceLatitude>0 anddifferenceLongitude>0 THENheading=NE ELSEIF differenceLatitude>0 anddifferenceLongitude<0 THENheading=NW ELSEIF differenceLatitude<0 anddifferenceLongitude<0 THENheading=SWENSEIF differenceLatitude<0 anddifferenceLongitude>0 THENheading=SE ENDIF

Algorithm 1 determines the cardinal direction using the values of the variables \(\text{current}\text{Latitude}\), \(\text{current}\text{Longitude}\), \(\text{before}\text{Latitude}\), and \(\text{before}\text{Longitude}\) when the location on the global positioning system (GPS) sensor in the smartphone changes. Each value of the variables \(\text{before}\text{Latitude}\) and \(\text{before}\text{Longitude}\) is changed after the 0.2 s sleep condition in which each current latitude and longitude are measured, and this measured value is replaced by the preceding values of latitude and longitude. In Algorithm 1,