latlon2unit(_home.lat, _home.lon, unitx, unity);
map_center_unit(unitx, unity);
map_set_autozoom(FALSE);
+ map_update_location_from_center();
vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
return TRUE;
(_menu_ac_none_item), TRUE);
map_center_unit(_pos.unitx, _pos.unity);
+ map_update_location_from_center();
vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
return TRUE;
gboolean menu_cb_goto_nearpoi(GtkAction * action)
{
gdouble lat, lon;
-PoiInfo *p;
+poi_info *p;
printf("%s()\n", __PRETTY_FUNCTION__);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_ac_none_item), TRUE);
map_center_unit(unitx, unity);
+ map_update_location_from_center();
} else {
MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
}
gboolean cmenu_cb_poi_route_to(GtkAction * action)
{
- PoiInfo poi;
+ poi_info poi;
printf("%s()\n", __PRETTY_FUNCTION__);
if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
gboolean cmenu_cb_poi_distance_to(GtkAction * action)
{
- PoiInfo poi;
+ poi_info poi;
printf("%s()\n", __PRETTY_FUNCTION__);
if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
gboolean cmenu_cb_poi_add_route(GtkAction * action)
{
- PoiInfo poi;
+ poi_info poi;
printf("%s()\n", __PRETTY_FUNCTION__);
if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
gboolean cmenu_cb_poi_add_way(GtkAction * action)
{
- PoiInfo poi;
+ poi_info poi;
printf("%s()\n", __PRETTY_FUNCTION__);
if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
#include "utils.h"
#include "gps.h"
#include "mapper-types.h"
+#include "gpx.h"
#define XML_DATE_FORMAT "%FT%T"
gchar XML_TZONE[7];
-void gpx_init(void)
+void
+gpx_init(void)
{
time_t time1;
struct tm time2;
(time2.tm_gmtoff / 60 / 60), (time2.tm_gmtoff / 60) % 60);
}
-gboolean write_gpx(Path * path, GnomeVFSHandle * handle)
+gboolean
+write_gpx(Path * path, GnomeVFSHandle * handle)
{
Point *curr = NULL;
WayPoint *wcurr = NULL;
data->unknown_depth = 1; \
}
-void
+static void
gpx_start_element(SaxData * data, const xmlChar * name, const xmlChar ** attrs)
{
vprintf("%s(%s)\n", __PRETTY_FUNCTION__, name);
/**
* Handle an end tag in the parsing of a GPX file.
*/
-void gpx_end_element(SaxData * data, const xmlChar * name)
+static void
+gpx_end_element(SaxData * data, const xmlChar * name)
{
vprintf("%s(%s)\n", __PRETTY_FUNCTION__, name);
/**
* Handle char data in the parsing of a GPX file.
*/
-void gpx_chars(SaxData * data, const xmlChar * ch, int len)
+static void
+gpx_chars(SaxData * data, const xmlChar * ch, int len)
{
guint i;
vprintf("%s()\n", __PRETTY_FUNCTION__);
* Handle an entity in the parsing of a GPX file. We don't do anything
* special here.
*/
-xmlEntityPtr gpx_get_entity(SaxData * data, const xmlChar * name)
+xmlEntityPtr
+gpx_get_entity(SaxData * data, const xmlChar * name)
{
vprintf("%s()\n", __PRETTY_FUNCTION__);
vprintf("%s(): return\n", __PRETTY_FUNCTION__);
/**
* Handle an error in the parsing of a GPX file.
*/
-void gpx_error(SaxData * data, const gchar * msg, ...)
+void
+gpx_error(SaxData * data, const gchar * msg, ...)
{
vprintf("%s()\n", __PRETTY_FUNCTION__);
vprintf("%s(): return\n", __PRETTY_FUNCTION__);
void hildon_banner_set_fraction(GtkWidget * widget, gdouble fraction)
{
gtk_progress_bar_set_fraction(_progress_item, fraction);
-if (fraction==1.0)
+if (fraction==1.0) {
gtk_widget_hide(_progress_item);
-else
+ gtk_progress_bar_set_text(_progress_item, "");
+} else
gtk_widget_show(_progress_item);
}
return lrint(lon/180*LATLON_MAX);
}
+gdouble
+mp_int2lon(gint lon)
+{
+return (gdouble)lon/LATLON_MAX*180;
+}
+
+gdouble
+mp_int2lat(gint lat)
+{
+
+}
+
gint
calculate_idistance(gint lat1, gint lon1, gint lat2, gint lon2)
{
}
/**
- * Calculate the distance between two lat/lon pairs. The distance is returned
- * in kilometer.
+ * Quick distance for comparing, skips the final square root
+ */
+gint
+calculate_idistance_cmp(gint lat1, gint lon1, gint lat2, gint lon2)
+{
+return ((lat1-lat2)*(lat1-lat2)+(lon1-lon2)*(lon1-lon2));
+}
+
+/**
+ * Calculate the distance between two lat/lon pairs.
+ * The distance is returned in kilometers.
+ *
*/
gdouble
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_PI_4l / 180.f);
+lon1*=(M_PI_4l / 180.f);
+lat2*=(M_PI_4l / 180.f);
+lon2*=(M_PI_4l / 180.f);
+
+dlat=lat2 - lat1;
+dlon=lon2 - lon1;
-dlat = lat2 - lat1;
-dlon = lon2 - lon1;
+slat=sinf(dlat / 2.f);
+slon=sinf(dlon / 2.f);
-slat = sinf(dlat / 2.f);
-slon = sinf(dlon / 2.f);
-a = (slat * slat) + (cosf(lat1) * cosf(lat2) * slon * slon);
+a=(slat * slat) + (cosf(lat1) * cosf(lat2) * slon * slon);
return ((2.f * atan2f(sqrtf(a), sqrtf(1.f - a))) * EARTH_RADIUS);
}
gint32 lon2mp_int(gdouble lon);
gint32 lat2mp_int(gdouble lat);
-gfloat calculate_distance(gfloat lat1, gfloat lon1, gfloat lat2, gfloat lon2);
+gdouble calculate_distance(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2);
gint calculate_idistance(gint lat1, gint lon1, gint lat2, gint lon2);
#endif
#include "mapper-types.h"
#include "ui-common.h"
#include "settings.h"
+#include "latlon.h"
Point _min_center = { -1, -1 };
Point _max_center = { -1, -1 };
guint _num_downloads=0;
guint _curr_download=0;
-static osm_location map_loc = {NULL, NULL, NULL};
+static osm_location map_loc = {NULL, NULL, NULL, FALSE, 0, 0};
static GHashTable *map_tile_hash = NULL;
typedef struct _map_tile_rdata map_tile_rdata;
map_update_location(gint x, gint y)
{
gint ilat, ilon;
-gdouble lat,lon, dist;
-gboolean fs, check_place=FALSE;
+gdouble lat,lon;
static gboolean inp=FALSE;
/* We run the gtk mainloop in progress callback so we can be called again, we don't like that */
ilat=lat2mp_int(lat);
ilon=lon2mp_int(lon);
-osm_progress_set_widget(_db, _progress_item);
-
-/* 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);
- check_place=FALSE;
- } else {
- check_place=FALSE;
- }
-} else {
- osm_way_free(map_loc.street);
- map_loc.street=osm_find_nearest_way(ilat, ilon);
- check_place=TRUE;
-}
+if (_gps.fix>1)
+ osm_set_way_range_from_speed(_gps.speed);
+else
+ osm_set_way_range(OSM_RANGE_WAY);
-_map_location_known=map_loc.street ? TRUE : FALSE;
+osm_progress_set_widget(_db, _progress_item);
+_map_location_known=osm_get_location_data(ilat, ilon, &map_loc);
_map_location_dist=map_loc.street ? map_loc.street->dist : 900000.0;
-
-if (check_place==TRUE) {
-
-fs=osm_find_nearest_place(NODE_PLACE_SUBURB, ilat, ilon, &map_loc.secondary);
-if (fs==TRUE && map_loc.secondary && map_loc.secondary->isin!=0) {
- if (osm_place_get(map_loc.secondary->isin, ilat, ilon, &map_loc.primary)==FALSE) {
- if (osm_find_nearest_place(NODE_PLACE_CITY, ilat, ilon, &map_loc.primary)==TRUE)
- g_printf("Near city: %s\n", map_loc.primary->name);
- else if (osm_find_nearest_place(NODE_PLACE_TOWN, ilat, ilon, &map_loc.primary)==TRUE)
- g_printf("Near town: %s\n", map_loc.primary->name);
- else
- g_printf("Unknown\n");
- } else {
- g_printf("In: %s\n", map_loc.primary ? map_loc.primary->name : "?");
- }
-} else if (map_loc.street && map_loc.street->isin!=0) {
- if (osm_place_get(map_loc.street->isin, ilat, ilon, &map_loc.primary)==FALSE) {
- g_printf("Street location not know.\n");
- } else {
- g_printf("Street is in: %s\n", map_loc.primary ? map_loc.primary->name : "?");
- }
-} else {
- if (osm_find_nearest_place(NODE_PLACE_CITY, ilat, ilon, &map_loc.primary)==TRUE)
- g_printf("Near city: %s\n", map_loc.primary->name);
- else if (osm_find_nearest_place(NODE_PLACE_TOWN, ilat, ilon, &map_loc.primary)==TRUE)
- g_printf("Near town: %s\n", map_loc.primary->name);
- else
- g_printf("Unknown\n");
-
-}
-}
-
map_set_place_information(map_loc.street, map_loc.primary, map_loc.secondary);
osm_progress_set_widget(_db, NULL);
inp=FALSE;
#include "hildon-mapper.h"
#include "utils.h"
-#include "poi.h"
-#include "route.h"
#include "mapper-types.h"
#include "settings.h"
#include "gps.h"
#include "map.h"
+#include "route.h"
+#include "track.h"
#include "bt.h"
#include "ui-common.h"
#include "db.h"
-#include "cb.h"
+#include "osm-db.h"
gfloat UNITS_CONVERT[] = {1.85200,1.15077945,1.f,};
#include "osm-db.h"
/* #define DEBUG_OSM */
-#define OSM_PLACE_CACHE_MAX_ITEMS (40)
-#define OSM_DB_PROGRESS_NUM (3000)
-#define OSM_START_RANGE (8192)
+#define OSM_PLACE_CACHE_MAX_ITEMS (64)
+#define OSM_DB_PROGRESS_NUM (5000)
+#define OSM_RANGE_START (8192)
+#define OSM_RANGE_STEP (8192)
+#define OSM_RANGE_STOP (49152)
struct sql_select_stmt {
sqlite3_stmt *select_way;
/* Cache hash tables */
static GHashTable *_place_cache;
+static gint way_dist_range=OSM_RANGE_WAY;
+
osm_way_node *osm_way_get_prev_node(osm_way *w);
osm_way_node *osm_way_get_next_node(osm_way *w);
/*****************************************************************************/
+void
+osm_set_way_range(gint sr)
+{
+way_dist_range=sr;
+}
+
+void
+osm_set_way_range_from_speed(gfloat speed)
+{
+if (speed>54)
+ way_dist_range=9000;
+else
+ way_dist_range=OSM_RANGE_WAY-lrint((speed/3)*1000);
+}
+
static int
osm_progress(void *ud)
{
* Get place with given id and distance to current location
*/
gboolean
-osm_place_get(guint32 id, gint lat, gint lon, osm_place *n)
+osm_place_get(guint32 id, gint lat, gint lon, osm_place **nr)
{
+osm_place *n;
+
+n=*nr;
n=osm_place_cache_lookup(id);
if (n) {
osm_place_update_distance(n, lat, lon);
{
GList *iter;
GList *w=NULL;
-guint range=OSM_START_RANGE;
+guint range=OSM_RANGE_START;
osm_way *cw=NULL;
gdouble pdist=START_DIST, dist_n, dist_p;
-while ((w=osm_find_nearest_way_nodes(lat, lon, range))==NULL && range<=65536) {
- range=range<<1;
+while ((w=osm_find_nearest_way_nodes(lat, lon, range))==NULL && range<=OSM_RANGE_STOP) {
+ range+=OSM_RANGE_STEP;
g_printf("Trying with range: %d\n", range);
}
return FALSE;
}
+/******************************************************************************/
+
+gboolean
+osm_get_location_data(gint lat, gint lon, osm_location *map_loc)
+{
+gdouble dist;
+gboolean fs, check_place=FALSE;
+static gboolean inp=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) {
+ if (dist>way_dist_range) {
+ osm_way_free(map_loc->street);
+ map_loc->street=osm_find_nearest_way(lat, lon);
+ check_place=FALSE;
+ } else {
+ check_place=FALSE;
+ }
+} else {
+ osm_way_free(map_loc->street);
+ map_loc->street=osm_find_nearest_way(lat, lon);
+ check_place=TRUE;
+}
+
+if (check_place==TRUE) {
+fs=osm_find_nearest_place(NODE_PLACE_SUBURB, lat, lon, &map_loc->secondary);
+if (fs==TRUE && map_loc->secondary && map_loc->secondary->isin!=0) {
+ if (osm_place_get(map_loc->secondary->isin, lat, lon, &(map_loc->primary))==FALSE) {
+ if (osm_find_nearest_place(NODE_PLACE_CITY, lat, lon, &map_loc->primary)==TRUE)
+ g_printf("Near city: %s\n", map_loc->primary->name);
+ else if (osm_find_nearest_place(NODE_PLACE_TOWN, lat, lon, &map_loc->primary)==TRUE)
+ g_printf("Near town: %s\n", map_loc->primary->name);
+ else
+ g_printf("Unknown\n");
+ } else {
+ g_printf("In: %s\n", map_loc->primary ? map_loc->primary->name : "?");
+ }
+} else if (map_loc->street && map_loc->street->isin!=0) {
+ if (osm_place_get(map_loc->street->isin, lat, lon, &map_loc->primary)==FALSE) {
+ g_printf("Street location not know.\n");
+ } else {
+ g_printf("Street is in: %s\n", map_loc->primary ? map_loc->primary->name : "?");
+ }
+} else {
+ if (osm_find_nearest_place(NODE_PLACE_CITY, lat, lon, &map_loc->primary)==TRUE)
+ g_printf("Near city: %s\n", map_loc->primary->name);
+ else if (osm_find_nearest_place(NODE_PLACE_TOWN, lat, lon, &map_loc->primary)==TRUE)
+ g_printf("Near town: %s\n", map_loc->primary->name);
+ else
+ g_printf("Unknown\n");
+
+}
+}
+
+return map_loc->street ? TRUE : FALSE;
+}
+
+
#include <glib.h>
#include "osm.h"
+#define OSM_RANGE_WAY (20000)
+
gboolean osm_init(void);
void osm_deinit(void);
+void osm_set_way_range_from_speed(gfloat speed);
+
void osm_progress_set_widget(sqlite3 *db, GtkProgressBar *w);
gboolean osm_way_get_nodes(osm_way *w);
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_get_location_data(gint lat, gint lon, osm_location *map_loc);
+
#endif
osm_way *street;
osm_place *primary;
osm_place *secondary;
+ gdouble valid;
+ gint lat;
+ gint lon;
};
#endif
guint _poi_zoom = 6;
-gboolean select_poi(guint unitx, guint unity, PoiInfo *poi);
+gboolean select_poi(guint unitx, guint unity, poi_info *poi);
-gboolean category_delete(GtkWidget * widget, DeletePOI *dpoi)
+gboolean category_delete(GtkWidget * widget, delete_poi *dpoi)
{
GtkWidget *dialog;
guint i;
GtkTextBuffer *desc_txt;
GtkTextIter begin, end;
gboolean results = TRUE;
- DeletePOI dpoi = { NULL, NULL, 0 };
+ delete_poi dpoi = { NULL, NULL, 0 };
poi_category *c;
printf("%s()\n", __PRETTY_FUNCTION__);
}
gboolean
-poi_delete_confirm(GtkWidget * widget, DeletePOI * dpoi)
+poi_delete_confirm(GtkWidget * widget, delete_poi * dpoi)
{
GtkWidget *dialog;
guint i;
}
gboolean
-select_poi(guint unitx, guint unity, PoiInfo *poi)
+select_poi(guint unitx, guint unity, poi_info *poi)
{
GtkWidget *dialog;
GtkWidget *list;
gboolean poi_dialog(POIAction action, guint unitx, guint unity)
{
- PoiInfo poi;
+ poi_info poi;
gchar slat1[10], slon1[10];
gchar *p_latlon;
GtkWidget *dialog;
GtkWidget *txt_scroll;
GtkTextBuffer *desc_txt;
GtkTextIter begin, end;
- DeletePOI dpoi = { NULL, NULL, 0 };
+ delete_poi dpoi = { NULL, NULL, 0 };
PoiCategoryEditInfo pcedit;
printf("%s()\n", __PRETTY_FUNCTION__);
struct _poi_categories {
node_type_t type;
- gchar *name, *desc;
+ const gchar *name, *desc;
};
static struct _poi_categories default_poi_categories[] = {
return FALSE;
}
-PoiInfo *
+poi_info *
poi_new(void)
{
-return g_slice_new0(PoiInfo);
+return g_slice_new0(poi_info);
}
void
-poi_free(PoiInfo *p)
+poi_free(poi_info *p)
{
-g_slice_free(PoiInfo, p);
+g_slice_free(poi_info, p);
}
poi_category *
}
gboolean
-poi_category_delete(DeletePOI *dpoi)
+poi_category_delete(delete_poi *dpoi)
{
if (!_db)
return FALSE;
gboolean
-poi_delete(DeletePOI *dpoi)
+poi_delete(delete_poi *dpoi)
{
if (!_db)
return FALSE;
return TRUE;
}
-PoiInfo *
+poi_info *
poi_find_nearest(gdouble lat, gdouble lon)
{
-PoiInfo *p;
+poi_info *p;
if (!_db)
return FALSE;
POI_TYPE_LANDMARK=1,
} poi_types_e;
-typedef struct _PoiDb PoiDb;
-struct _PoiDb {
+typedef struct _poi_db poi_db;
+struct _poi_db {
sqlite3 *db;
gchar *file;
guint zoom;
};
-typedef struct _PoiData PoiData;
-struct _PoiData {
+typedef struct _poi_data poi_data;
+struct _poi_data {
gdouble lat;
gdouble lon;
gchar *name;
};
/** Data to describe a POI. */
-typedef struct _PoiInfo PoiInfo;
-struct _PoiInfo {
+typedef struct _poi_info poi_info;
+struct _poi_info {
guint poi_id;
guint cat_id;
gdouble lat;
};
/** Data used during action: add or edit category/poi **/
-typedef struct _DeletePOI DeletePOI;
-struct _DeletePOI {
+typedef struct _delete_poi delete_poi;
+struct _delete_poi {
GtkWidget *dialog;
gchar *txt_label;
guint id;
gboolean poi_db_create(sqlite3 *db);
gboolean poi_db_prepare(sqlite3 *db);
-PoiInfo *poi_new(void);
-void poi_free(PoiInfo *p);
+poi_info *poi_new(void);
+void poi_free(poi_info *p);
gboolean poi_get_list(guint unitx, guint unity, GtkListStore **store, guint *num_cats);
gboolean poi_update(gint poi_id, gint cat_id, gchar *poi_label, gchar *poi_desc);
gboolean poi_add(gdouble lat, gdouble lon, gint cat_id, gchar *poi_label, gchar *poi_desc);
-gboolean poi_delete(DeletePOI * dpoi);
+gboolean poi_delete(delete_poi * dpoi);
poi_category *poi_category_new(void);
void poi_category_free(poi_category *c);
gboolean poi_category_get(gint cat_id, poi_category **c);
-gboolean poi_category_delete(DeletePOI * dpoi);
+gboolean poi_category_delete(delete_poi * dpoi);
gboolean poi_category_update(gint cat_id, poi_category *c);
-PoiInfo *poi_find_nearest(gdouble lat, gdouble lon);
+poi_info *poi_find_nearest(gdouble lat, gdouble lon);
gboolean poi_category_toggle(gint cat_id, gboolean cat_enabled);
GtkListStore *poi_category_generate_store();
#if 0
void latlon2unit(gdouble lat, gdouble lon, gint *unitx_, gint *unity_)
{
- gdouble tmp;
+gdouble tmp;
- gint unitx = &unitx_;
- gint unity = &unity_;
+gint unitx = &unitx_;
+gint unity = &unity_;
- unitx = (lon + 180.f) * (WORLD_SIZE_UNITS / 360.f) + 0.5f;
- tmp = sinf(lat * (PI / 180.f));
- unity = 0.5f + (WORLD_SIZE_UNITS / MERCATOR_SPAN)
- * (logf((1.f + tmp) / (1.f - tmp)) * 0.5f - MERCATOR_TOP);
+unitx = (lon + 180.f) * (WORLD_SIZE_UNITS / 360.f) + 0.5f;
+tmp = sinf(lat * (PI / 180.f));
+unity = 0.5f + (WORLD_SIZE_UNITS / MERCATOR_SPAN)
+ * (logf((1.f + tmp) / (1.f - tmp)) * 0.5f - MERCATOR_TOP);
}
void unit2latlon(gint unitx, gint unity, gdouble *lat, gdouble *lon)
} \
}
-gint download_comparefunc(const ProgressUpdateInfo * a,
- const ProgressUpdateInfo * b, gpointer user_data);
-gdouble calculate_distance(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2);
+void sound_noise(void);
+gint download_comparefunc(const ProgressUpdateInfo * a, const ProgressUpdateInfo * b, gpointer user_data);
void deg_format(DegFormat degformat, gdouble coor, gchar *scoor, gchar neg_char, gchar pos_char);
void integerize_data();