/**
* @brief Converts a lat/lon into a text formatted text string.
- * @param lat The latitude
- * @param lng The longitude
+ * @param lat The latitude (if lat is 360 or greater, the latitude will be omitted)
+ * @param lng The longitude (if lng is 360 or greater, the longitude will be omitted)
* @param fmt The format to use.
- * @li DEGREES=>(45.5000N 100.9000S)
- * @li DEGREES_MINUTES=>(45 30.))00N 100 120.54.0000S)
- * @li DEGREES_MINUTES_SECONDS=>(4530.0000N 12054.0000S)
+ * @li DEGREES=>Degrees with decimal places, i.e. 20.5000°N 110.5000°E
+ * @li DEGREES_MINUTES=>Degrees and minutes, i.e. 20°30.00'N 110°30.00'E
+ * @li DEGREES_MINUTES_SECONDS=>Degrees, minutes and seconds, i.e. 20°30'30.00"N 110°30'30"E
*
*
- * @param buffer A buffer large enough to hold the output + a terminating NULL (26 bytes)
+ * @param buffer A buffer large enough to hold the output + a terminating NULL (up to 31 bytes)
* @param size The size of the buffer
*
*/
char lng_c='E';
float lat_deg,lat_min,lat_sec;
float lng_deg,lng_min,lng_sec;
+ int size_used=0;
if (lng < 0) {
lng=-lng;
{
case DEGREES_DECIMAL:
- snprintf(buffer,size,"%02.6f%c %03.7f%c",lat,lat_c,lng,lng_c);
+ if (lat<360)
+ size_used+=snprintf(buffer+size_used,size-size_used,"%02.6f°%c",lat,lat_c);
+ if ((lat<360)&&(lng<360))
+ size_used+=snprintf(buffer+size_used,size-size_used," ");
+ if (lng<360)
+ size_used+=snprintf(buffer+size_used,size-size_used,"%03.7f°%c",lng,lng_c);
break;
case DEGREES_MINUTES:
- snprintf(buffer,size,"%02.0f %07.4f%c %03.0f %07.4f%c",floor(lat_deg),lat_min , lat_c, floor(lng), lng_min, lng_c);
- break;
+ if (lat<360)
+ size_used+=snprintf(buffer+size_used,size-size_used,"%02.0f°%07.4f' %c",floor(lat_deg),lat_min,lat_c);
+ if ((lat<360)&&(lng<360))
+ size_used+=snprintf(buffer+size_used,size-size_used," ");
+ if (lng<360)
+ size_used+=snprintf(buffer+size_used,size-size_used,"%03.0f°%07.4f' %c",floor(lng_deg),lng_min,lng_c);
+ break;
case DEGREES_MINUTES_SECONDS:
- snprintf(buffer,size,"%02.0f%07.4f%c %03.0f%07.4f%c",floor(lat), fmod(lat*60,60), lat_c, floor(lng), fmod(lng*60,60), lng_c);
+ if (lat<360)
+ size_used+=snprintf(buffer+size_used,size-size_used,"%02.0f°%02.0f'%05.2f\" %c",floor(lat_deg),floor(lat_min),lat_sec,lat_c);
+ if ((lat<360)&&(lng<360))
+ size_used+=snprintf(buffer+size_used,size-size_used," ");
+ if (lng<360)
+ size_used+=snprintf(buffer+size_used,size-size_used,"%03.0f°%02.0f'%05.2f\" %c",floor(lng_deg),floor(lng_min),lng_sec,lng_c);
break;
case attr_position_magnetic_direction:
return g_strdup_printf("%d",attr->u.num);
case attr_position_coord_geo:
- coord_format(attr->u.coord_geo->lat,attr->u.coord_geo->lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
- return g_strdup(buffer);
+ if (format) {
+ if (!strcmp(format,"pos_degmin"))
+ {
+ coord_format(attr->u.coord_geo->lat,attr->u.coord_geo->lng,DEGREES_MINUTES,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ }
+ else if (!strcmp(format,"pos_deg"))
+ {
+ coord_format(attr->u.coord_geo->lat,attr->u.coord_geo->lng,DEGREES_DECIMAL,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ }
+ else if (!strcmp(format,"lat_degminsec"))
+ {
+ coord_format(attr->u.coord_geo->lat,360,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ }
+ else if (!strcmp(format,"lat_degmin"))
+ {
+ coord_format(attr->u.coord_geo->lat,360,DEGREES_MINUTES,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ }
+ else if (!strcmp(format,"lat_deg"))
+ {
+ coord_format(attr->u.coord_geo->lat,360,DEGREES_DECIMAL,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ }
+ else if (!strcmp(format,"lng_degminsec"))
+ {
+ coord_format(360,attr->u.coord_geo->lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ }
+ else if (!strcmp(format,"lng_degmin"))
+ {
+ coord_format(360,attr->u.coord_geo->lng,DEGREES_MINUTES,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ }
+ else if (!strcmp(format,"lng_deg")) {
+ coord_format(360,attr->u.coord_geo->lng,DEGREES_DECIMAL,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ }
+ } else { //Covers format==pos_degminsec too
+ coord_format(attr->u.coord_geo->lat,attr->u.coord_geo->lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
+ return g_strdup(buffer);
+ }
case attr_destination_time:
if (!format || (strcmp(format,"arrival") && strcmp(format,"remaining")))
break;
tm.tm_min = 0;
tm.tm_hour = 0;
days = (mktime(&text_tm0) - mktime(&tm) + 43200) / 86400;
- }
+ }
return format_time(&text_tm, days);
case attr_length:
case attr_destination_length: