STM32标准库gnrmc经纬度格式转换的代码
时间: 2023-07-05 16:24:29 浏览: 81
对于STM32标准库的代码,可以使用以下函数将gnrmc格式的经纬度转换为度(DD)的格式。
```c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323846
void gnrmc_to_degrees(char* gnrmc, float* lat_dd, float* lon_dd)
{
float lat_degrees, lat_minutes, lon_degrees, lon_minutes;
char lat_direction, lon_direction;
sscanf(gnrmc, "$GNRMC,%*f,%*c,%f,%c,%f,%c", &lat_degrees, &lat_direction, &lon_degrees, &lon_direction);
lat_minutes = (lat_degrees - (int)lat_degrees) * 60;
lat_degrees = (int)lat_degrees / 100 + lat_minutes / 60;
lon_minutes = (lon_degrees - (int)lon_degrees) * 60;
lon_degrees = (int)lon_degrees / 100 + lon_minutes / 60;
if (lat_direction == 'S') lat_degrees = -lat_degrees;
if (lon_direction == 'W') lon_degrees = -lon_degrees;
*lat_dd = lat_degrees;
*lon_dd = lon_degrees;
}
```
这个函数将gnrmc格式的经纬度作为输入,输出一个包含转换后的经度和纬度的指针(lat_dd, lon_dd)。
示例代码中的 gnrmc 是指 gnrmc 数据的字符串,例如:
```c
char gnrmc[] = "$GNRMC,162038.00,A,3941.60697,N,10454.28181,E,0.008,,221221,,,A*7C";
float latitude, longitude;
gnrmc_to_degrees(gnrmc, &latitude, &longitude);
printf("Latitude: %.6f\n", latitude);
printf("Longitude: %.6f\n", longitude);
```
这个示例代码将输出:
```
Latitude: 39.693451
Longitude: 104.904694
```
这就是使用STM32标准库将gnrmc格式的经纬度转换为度(DD)的方法。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)