From e935da44cef27f099bffcfc6e26f560dcde3be33 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Tue, 24 Jul 2007 23:43:15 +0300 Subject: [PATCH] Start to use a static location structure, with street/primary/secondary location. Check if we are on the same way as last time and skip database query if so. Use idle function to update location. (For now, a thread would be nicer so the UI won't block even if the query would take time). --- src/map.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/map.c b/src/map.c index c926cd1..c9e914e 100644 --- a/src/map.c +++ b/src/map.c @@ -57,6 +57,7 @@ static gint _map_mode=0; guint _num_downloads=0; guint _curr_download=0; +static osm_location map_loc = {NULL, NULL, NULL}; static GHashTable *map_tile_hash = NULL; void map_render_paths(); @@ -947,6 +948,20 @@ void map_move_mark() vprintf("%s(): return\n", __PRETTY_FUNCTION__); } +gboolean +map_update_location_from_gps() +{ +map_update_location(_pos.unitx, _pos.unity); +return FALSE; +} + +gboolean +map_update_location_from_center() +{ +map_update_location(_center.unitx, _center.unity); +return FALSE; +} + /** * Make sure the mark is up-to-date. This function triggers a panning of * the view if the mark is appropriately close to the edge of the view. @@ -972,7 +987,7 @@ void refresh_mark() speed_limit(); if (_center_mode>0) - map_update_location(_pos.unitx, _pos.unity); + g_idle_add((GSourceFunc)map_update_location_from_gps, NULL); vprintf("%s(): return\n", __PRETTY_FUNCTION__); } @@ -1383,8 +1398,7 @@ static void map_update_location(gint x, gint y) { gint ilat, ilon; -gdouble lat,lon; -osm_way *street; +gdouble lat,lon, dist; osm_place mplace; osm_place splace; PoiInfo *p; @@ -1394,11 +1408,21 @@ unit2latlon(x, y, lat, lon); ilat=lat2mp_int(lat); ilon=lon2mp_int(lon); +/* Check if we are still near the same way as last time */ +if (map_loc.street && osm_way_distance(ilat, ilon, map_loc.street->node_f, map_loc.street->node_t, &dist)==TRUE) { + if (dist>15000.0) { + osm_way_free(map_loc.street); + map_loc.street=osm_find_nearest_way(ilat, ilon); + } +} else { + osm_way_free(map_loc.street); + map_loc.street=osm_find_nearest_way(ilat, ilon); +} + mplace.name=NULL; splace.name=NULL; p=poi_find_nearest(lat, lon); -street=osm_find_nearest_way(ilat, ilon); osm_find_nearest_place(NODE_PLACE_SUBURB, ilat, ilon, &splace); if (splace.isin!=0) { @@ -1412,8 +1436,8 @@ if (splace.isin!=0) { } else { g_printf("In %s\n", mplace.name); } -} else if (street && street->isin!=0) { - if (osm_place_get(street->isin, ilat, ilon, &mplace)==FALSE) { +} else if (map_loc.street && map_loc.street->isin!=0) { + if (osm_place_get(map_loc.street->isin, ilat, ilon, &mplace)==FALSE) { } else { g_printf("In %s\n", mplace.name); @@ -1428,8 +1452,7 @@ if (splace.isin!=0) { } -map_set_place_information(street, &mplace, &splace, p); -osm_way_free(street); +map_set_place_information(map_loc.street, &mplace, &splace, p); } gboolean map_cb_scroll_event(GtkWidget * widget, GdkEventScroll * event) @@ -1511,10 +1534,14 @@ gint ux,uy; break; } +#if 0 ux = x2unit((gint) (event->x + 0.5)); uy = y2unit((gint) (event->y + 0.5)); - map_update_location(ux, uy); +#endif + + g_idle_add((GSourceFunc)map_update_location_from_center, NULL); + map_center_unit(x2unit((gint) (event->x + 0.5)), y2unit((gint) (event->y + 0.5))); -- 2.39.5