From: Kaj-Michael Lang Date: Fri, 10 Aug 2007 08:02:08 +0000 (+0300) Subject: Use heading difference to check if we have moved away from the old road. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=871a78bf2f85d91252e8a14b9ed34b6a3bbba2ab;p=mapper Use heading difference to check if we have moved away from the old road. Remove some dead old way code. Misc other fixes. --- diff --git a/src/osm-db.c b/src/osm-db.c index 861c520..b87c13c 100644 --- a/src/osm-db.c +++ b/src/osm-db.c @@ -12,7 +12,7 @@ #include "osm.h" #include "latlon.h" - +#include "gps.h" #include "osm-db.h" /* #define DEBUG_OSM */ @@ -394,53 +394,6 @@ if (SQLITE_ROW == sqlite3_step(sql.select_near_place)) { return FALSE; } -#if 0 -/* Way helper */ -static GList * -osm_find_nearest_way_nodes(gint lat, gint lon, guint range) -{ -GList *ways=NULL; -osm_way *w; -gulong tms; -gint wc=0; - -sqlite3_reset(sql.select_way); -sqlite3_clear_bindings(sql.select_way); - -if (SQLITE_OK != sqlite3_bind_int(sql.select_way, 1, lat) || - SQLITE_OK != sqlite3_bind_int(sql.select_way, 2, lon) || - SQLITE_OK != sqlite3_bind_int(sql.select_way, 3, range) || - SQLITE_OK != sqlite3_bind_int(sql.select_way, 4, WAY_ROAD_START) || - SQLITE_OK != sqlite3_bind_int(sql.select_way, 5, WAY_ROAD_END)) { - g_printerr("Failed to bind values for way\n"); - return NULL; -} - -g_timer_start(dbt); - -while (SQLITE_ROW == sqlite3_step(sql.select_way)) { - guint32 dist; - - wc++; - w=g_slice_new0(osm_way); - w->id=sqlite3_column_int(sql.select_way, 0); - w->type=sqlite3_column_int(sql.select_way, 1); - w->nodecnt=sqlite3_column_int(sql.select_way, 2); - w->flags=sqlite3_column_int(sql.select_way, 3); - dist=sqlite3_column_int(sql.select_way, 4); - w->dist=sqrt((gdouble)dist); - w->node_num=sqlite3_column_int(sql.select_way, 5); - ways=g_list_prepend(ways, w); -} - -g_timer_stop(dbt); -g_printf("Query took: %f sec, found: %d ways\n", g_timer_elapsed(dbt, &tms), wc); - -return ways; -} - -#else - /* Way helper */ static GList * osm_find_nearest_way_nodes(gint lat, gint lon, guint range) @@ -493,8 +446,6 @@ g_printf("Query took: %f sec, found: %d ways\n", g_timer_elapsed(dbt, &tms), wc) return ways; } -#endif - /*****************************************************************************/ static inline gdouble @@ -802,7 +753,7 @@ if (map_loc->valid==FALSE) { /* Check if we are still near the same way as last time */ if (map_loc->street && osm_way_distance(lat, lon, map_loc->street->node_f, map_loc->street->node_t, &dist)==TRUE) { /* We are probably on the same way as last time */ - if (dist>(gdouble)way_dist_range) { + if ( (dist>(gdouble)way_dist_range) || (fabs(_gps.heading-map_loc->heading)>10.0)) { /* We have moved a large amount, check way again */ g_printf("*** dist %f over range, checking again\n", dist); osm_way_free(map_loc->street); @@ -839,6 +790,11 @@ if (map_loc->street && osm_way_distance(lat, lon, map_loc->street->node_f, map_l } } +if (map_loc->changed==TRUE) { + map_loc->heading=_gps.heading; + map_loc->speed=_gps.speed; +} + g_printf("D: %ld %ld\n", d,(gulong)way_dist_range); if (check_place==TRUE && d>way_dist_range*4) { diff --git a/src/osm-db.h b/src/osm-db.h index 819981c..edffca0 100644 --- a/src/osm-db.h +++ b/src/osm-db.h @@ -13,6 +13,7 @@ void osm_set_way_range_from_speed(gfloat speed); void osm_set_way_range(guint sr); void osm_progress_set_widget(sqlite3 *db, GtkProgressBar *w); +gboolean osm_db_prepare(sqlite3 *db); gboolean osm_way_get_nodes(osm_way *w); gboolean osm_way_get_name(osm_way *w); @@ -22,6 +23,13 @@ gboolean osm_find_nearest_place(node_type_t type, gint lat, gint lon, osm_place osm_way *osm_find_nearest_way(gint lat, gint lon); gboolean osm_way_distance(gint lat, gint lon, osm_way_node *f, osm_way_node *t, gdouble *d); +gboolean osm_place_get(guint32 id, gint lat, gint lon, osm_place **nr); + gboolean osm_get_location_data(gint lat, gint lon, osm_location *map_loc); +osm_way_node *osm_way_node_new(guint id, gint lat, gint lon, gint flags); + +void osm_way_node_free(osm_way_node *n); +void osm_way_free(osm_way *w); + #endif