return;
}
+/**
+ * @brief Converts a lat/lon into a text formatted text string.
+ * @param lat The latitude
+ * @param lng The longitude
+ * @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)
+ *
+ *
+ * @param buffer A buffer large enough to hold the output + a terminating NULL (26 bytes)
+ * @param size The size of the buffer
+ *
+ */
+void coord_format(float lat,float lng, enum coord_format fmt, char * buffer, int size)
+{
+
+ char lat_c='N';
+ char lng_c='E';
+ float lat_deg,lat_min,lat_sec;
+ float lng_deg,lng_min,lng_sec;
+
+ if (lng < 0) {
+ lng=-lng;
+ lng_c='W';
+ }
+ if (lat < 0) {
+ lat=-lat;
+ lat_c='S';
+ }
+ lat_deg=lat;
+ lat_min=(lat-floor(lat_deg))*60;
+ lat_sec=fmod(lat*3600,60);
+ lng_deg=lng;
+ lng_min=(lng-floor(lng_deg))*60;
+ lng_sec=fmod(lng*3600,60);
+ switch(fmt)
+ {
+
+ case DEGREES_DECIMAL:
+ snprintf(buffer,size,"%02.6f%c %03.7f%c",lat,lat_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;
+ 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);
+ break;
+
+
+ }
+
+}
+
/** @} */
double z; /*!< Z-Value */
};
+/**
+ * An enumeration of formats for printing geographic coordinates in.
+ *
+ */
+enum coord_format
+{
+ /**
+ * Degrees with decimal places.
+ * Ie 20.5000 N 110.5000 E
+ */
+ DEGREES_DECIMAL,
+
+ /**
+ * Degrees and minutes.
+ * ie 20 30.00 N 110 30.00 E
+ */
+ DEGREES_MINUTES,
+ /**
+ * Degrees, minutes and seconds.
+ * ie 20 30 30.00 N 110 30 30 E
+ */
+ DEGREES_MINUTES_SECONDS
+};
+
enum projection;
struct attr;
int coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2);
int coord_rect_contains(struct coord_rect *r, struct coord *c);
void coord_rect_extend(struct coord_rect *r, struct coord *c);
-
+void coord_format(float lat,float lng, enum coord_format, char * buffer, int size);
#endif
g.lng=(triple(&sub->center.lng)+(pnt->lng_delta << shift))*conv;
g.lat=(triple(&sub->center.lat)+(pnt->lat_delta << shift))*conv;
printf("%f %f\n", g.lng, g.lat);
- transform_geo_text(&g, buffer);
+ coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,
+ buffer,sizeof(buffer));
printf("%s\n", buffer);
dump_label_offset(mr, triple_u(&pnt->lbl_offset));
if (pnt->info & 0x80)
static void
statusbar_gps_update(struct statusbar_priv *this, int sats, int qual, double lng, double lat, double height, double direction, double speed)
{
- char lat_c='N';
- char lng_c='E';
- char *dirs[]={_("N"),_("NE"),_("E"),_("SE"),_("S"),_("SW"),_("W"),_("NW"),_("N")};
+ char *dirs[]={_("N"),_("NE"),_("E"),_("SE"),_("S"),_("SW"),_("W"),_("NW"),_("N")};
char *dir;
int dir_idx;
+ char pos_text[26];
- if (lng < 0) {
- lng=-lng;
- lng_c='W';
- }
- if (lat < 0) {
- lat=-lat;
- lat_c='S';
- }
- dir_idx=(direction+22.5)/45;
+ coord_format(lat,lng,DEGREES_MINUTES_SECONDS,pos_text,sizeof(pos_text));
dir=dirs[dir_idx];
- sprintf(this->gps_text, "GPS %02d/%02d %02.0f%07.4f%c %03.0f%07.4f%c %4.0fm %3.0f°%-2s %3.0fkm/h", sats, qual, floor(lat), fmod(lat*60,60), lat_c, floor(lng), fmod(lng*60,60), lng_c, height, direction, dir, speed);
+ sprintf(this->gps_text, "GPS %02d/%02d %s %4.0fm %3.0f°%-2s %3.0fkm/h", sats, qual, pos_text, height, direction, dir, speed);
gtk_label_set_text(GTK_LABEL(this->gps), this->gps_text);
}
char buffer[128];
double lng, lat, direction=0, height=0, speed=0, hdop=0;
int sats=0, qual=0;
- char lat_c='N';
- char lng_c='E';
int status;
char *dirs[]={_("N"),_("NE"),_("E"),_("SE"),_("S"),_("SW"),_("W"),_("NW"),_("N")};
char *dir;
return;
lng=attr.u.coord_geo->lng;
lat=attr.u.coord_geo->lat;
- if (lng < 0) {
- lng=-lng;
- lng_c='W';
- }
- if (lat < 0) {
- lat=-lat;
- lat_c='S';
- }
if (vehicle_get_attr(v, attr_position_fix_type, &attr, NULL))
status=attr.u.num;
if (vehicle_get_attr(v, attr_position_direction, &attr, NULL))
sats=attr.u.num;
if (vehicle_get_attr(v, attr_position_qual, &attr, NULL))
qual=attr.u.num;
- sprintf(this->gps_text,"GPS:%s %02d/%02d HD:%02.2f %02.0f%07.4f%c %03.0f%07.4f%c %4.0fm %3.0f°%-2s %3.0fkm/h",
+ coord_format(lat,lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
+ sprintf(this->gps_text,"GPS:%s %02d/%02d HD:%02.2f %s %4.0fm %3.0f°%-2s %3.0fkm/h",
status_fix2str(status),
- sats, qual, hdop, floor(lat), fmod(lat*60,60),
- lat_c, floor(lng), fmod(lng*60,60), lng_c, height,
+ sats, qual, hdop, buffer, height,
direction, dir, speed);
gtk_label_set_text(GTK_LABEL(this->gps), this->gps_text);
}
c.x = pc->x;
c.y = pc->y;
transform_to_geo(transform_get_projection(navit_get_trans(nav)), &c, &g);
- transform_geo_text(&g, buffer_geo);
+ coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,buffer_geo,sizeof(buffer_geo));
sprintf(buffer,"Map Point %s", buffer_geo);
navit_set_destination(nav, pc, buffer);
}
c.x = pc->x;
c.y = pc->y;
transform_to_geo(pc->pro, &c, &g);
- transform_geo_text(&g, buffer_geo);
+ coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,buffer_geo,sizeof(buffer_geo));
sprintf(buffer,"Map Point %s", buffer_geo);
if (!gui_add_bookmark(navit_get_gui(nav), pc, buffer))
navit_add_bookmark(nav, pc, buffer);
men=popup_printf(popup, menu_type_submenu, _("Point 0x%x 0x%x"), co.x, co.y);
popup_printf(men, menu_type_menu, _("Screen coord : %d %d"), p->x, p->y);
transform_to_geo(transform_get_projection(navit_get_trans(nav)), &co, &g);
- transform_geo_text(&g, buffer);
+ coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,buffer,sizeof(buffer));
popup_printf(men, menu_type_menu, "%s", buffer);
popup_printf(men, menu_type_menu, "%f %f", g.lat, g.lng);
dbg(0,"%p %p\n", nav, &c);
}
-void
-transform_geo_text(struct coord_geo *g, char *buffer)
-{
- double lng=g->lng;
- double lat=g->lat;
- char lng_c='E';
- char lat_c='N';
-
- if (lng < 0) {
- lng=-lng;
- lng_c='W';
- }
- if (lat < 0) {
- lat=-lat;
- lat_c='S';
- }
-
- sprintf(buffer,"%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);
-
-}
#define TWOPI (M_PI*2)
#define GC2RAD(c) ((c) * TWOPI/(1<<24))
long transform_get_scale(struct transformation *t);
void transform_set_scale(struct transformation *t, long scale);
int transform_get_order(struct transformation *t);
-void transform_geo_text(struct coord_geo *g, char *buffer);
double transform_scale(int y);
double transform_distance(enum projection pro, struct coord *c1, struct coord *c2);
double transform_polyline_length(enum projection pro, struct coord *c, int count);