unit2latlon(unitx, unity, lat, lon);
- snprintf(buffer, sizeof(buffer), "%s: %.02f %s", _("Distance"),
+ snprintf(buffer, sizeof(buffer), "%s: %.02lf %s", _("Distance"),
calculate_distance(_gps.lat, _gps.lon, lat, lon)
* UNITS_CONVERT[_units], UNITS_TEXT[_units]);
MACRO_BANNER_SHOW_INFO(_window, buffer);
gdouble dlat, dlon, slat, slon, a;
/* Convert to radians. */
-lat1*=(M_PI_4l / 180.f);
-lon1*=(M_PI_4l / 180.f);
-lat2*=(M_PI_4l / 180.f);
-lon2*=(M_PI_4l / 180.f);
+lat1*=(M_PIl / 180.f);
+lon1*=(M_PIl / 180.f);
+lat2*=(M_PIl / 180.f);
+lon2*=(M_PIl / 180.f);
dlat=lat2 - lat1;
dlon=lon2 - lon1;
return ((2.f * atan2(sqrt(a), sqrt(1.f - a))) * EARTH_RADIUS);
}
+gdouble
+calculate_course(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2)
+{
+gdouble c,dlon,x,y;
+
+lat1*=(M_PIl / 180.f);
+lon1*=(M_PIl / 180.f);
+lat2*=(M_PIl / 180.f);
+lon2*=(M_PIl / 180.f);
+
+dlon=lon2-lon1;
+y=sin(dlon)*cos(lat2);
+x=cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(dlon);
+c=atan2(y,x);
+g_printf("H: %lf %lf\n", x ,y, c);
+
+/* Fixup for compass */
+c*=180.f/M_PIl;
+c=c+360 % 360;
+return c;
+}
gdouble calculate_distance(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2);
gulong calculate_idistance(gint lat1, gint lon1, gint lat2, gint lon2);
gulong calculate_idistance_cmp(gint lat1, gint lon1, gint lat2, gint lon2);
+gdouble calculate_course(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2);
#endif
gtk_label_set_label(GTK_LABEL(info_banner.location), buffer);
}
+static void
+map_update_destination(gdouble lat, gdouble lon)
+{
+if (_dest.valid) {
+ gchar buffer[32];
+ gdouble dt=calculate_distance(lat, lon, _dest.lat, _dest.lon);
+ gdouble dh=calculate_course(lat, lon, _dest.lat, _dest.lon);
+ snprintf(buffer, sizeof(buffer), "%.02f %s (%0.02f)", dt * UNITS_CONVERT[_units], UNITS_TEXT[_units], dh);
+ gtk_label_set_label(GTK_LABEL(info_banner.distance), buffer);
+} else {
+ gtk_label_set_label(GTK_LABEL(info_banner.distance), "");
+}
+}
+
static void
map_update_location(gint x, gint y, gboolean force)
{
map_set_place_information(NULL, NULL, NULL);
osm_progress_set_widget(_db, NULL);
-if (_dest.valid) {
- gchar buffer[32];
- gdouble dt=calculate_distance(lat, lon, _dest.lat, _dest.lon);
- snprintf(buffer, sizeof(buffer), "%.02f %s", dt * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
- gtk_label_set_label(GTK_LABEL(info_banner.distance), buffer);
-} else {
- gtk_label_set_label(GTK_LABEL(info_banner.distance), "");
-}
+map_update_destination(lat, lon);
inp=FALSE;
}