]> err.no Git - mapper/commitdiff
Display course/heading to target.
authorKaj-Michael Lang <milang@angel.tal.org>
Fri, 10 Aug 2007 10:16:55 +0000 (13:16 +0300)
committerKaj-Michael Lang <milang@angel.tal.org>
Fri, 10 Aug 2007 10:16:55 +0000 (13:16 +0300)
src/cb.c
src/latlon.c
src/latlon.h
src/map.c

index c312cfc213012e0e00d22ff62585463b17d5c22d..ac8e02bb4a63dce00e003ae9c2e2fb6fe01398a7 100644 (file)
--- a/src/cb.c
+++ b/src/cb.c
@@ -1025,7 +1025,7 @@ void cmenu_distance_to(guint unitx, guint unity)
 
        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);
index df7bd707f3ba827d35ba267030adfd1a8c81b8e4..3cb06c96c460bf708c4aaeab56eeb58506f3c3b0 100644 (file)
@@ -67,10 +67,10 @@ calculate_distance(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2)
 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;
@@ -83,3 +83,24 @@ a=(slat * slat) + (cos(lat1) * cos(lat2) * slon * slon);
 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;
+}
index 1e4a581b8a1c57ba960e6404c4ab34ca17c04146..162b4bf93eb1353844c5d355babe2d5454d93ce0 100644 (file)
@@ -13,5 +13,6 @@ gint32 lat2mp_int(gdouble lat);
 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
index a2ae11a7b1562b1fe77a15f57cbc5456a2a8a4b8..e754687effe8bc4bdb793ab06cbd95fa5e406e2f 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -1396,6 +1396,20 @@ if (!s && !mp && !sp) {
 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)
 {
@@ -1426,14 +1440,7 @@ else
        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;
 }