2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (c) 2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * @short_description: the class for OSRM
26 * The #OsrmRouting class handles OSRM
27 * service as routing engine.
29 * Technical details are available here:
30 * http://project-osrm.org/
40 #include <glib/gstdio.h>
44 /* See API references: https://github.com/DennisOSRM/Project-OSRM/wiki/Server-api */
45 #define OSRM_DIRECTIONS_STRING "router.project-osrm.org/viaroute?loc=%s,%s&loc=%s,%s&output=gpx"
47 static DownloadMapOptions osrms_routing_options = { FALSE, FALSE, "http://map.project-osrm.org/", 0, NULL };
49 static void osrm_routing_finalize ( GObject *gob );
51 static gchar *osrm_routing_get_url_for_coords ( VikRoutingEngine *self, struct LatLon start, struct LatLon end );
52 static DownloadMapOptions *osrm_routing_get_download_options ( VikRoutingEngine *self );
54 G_DEFINE_TYPE (OsrmRouting, osrm_routing, VIK_ROUTING_ENGINE_TYPE)
56 static void osrm_routing_class_init ( OsrmRoutingClass *klass )
58 GObjectClass *object_class;
59 VikRoutingEngineClass *parent_class;
61 object_class = G_OBJECT_CLASS (klass);
63 object_class->finalize = osrm_routing_finalize;
65 parent_class = VIK_ROUTING_ENGINE_CLASS (klass);
67 parent_class->get_url_for_coords = osrm_routing_get_url_for_coords;
68 parent_class->get_download_options = osrm_routing_get_download_options;
71 OsrmRouting *osrm_routing_new ()
73 return OSRM_ROUTING ( g_object_new ( OSRM_ROUTING_TYPE,
80 static void osrm_routing_init ( OsrmRouting *vlp )
84 static void osrm_routing_finalize ( GObject *gob )
86 G_OBJECT_GET_CLASS(gob)->finalize(gob);
89 static DownloadMapOptions *
90 osrm_routing_get_download_options ( VikRoutingEngine *self )
92 return &osrms_routing_options;
96 osrm_routing_get_url_for_coords ( VikRoutingEngine *self, struct LatLon start, struct LatLon end )
98 gchar startlat[G_ASCII_DTOSTR_BUF_SIZE], startlon[G_ASCII_DTOSTR_BUF_SIZE];
99 gchar endlat[G_ASCII_DTOSTR_BUF_SIZE], endlon[G_ASCII_DTOSTR_BUF_SIZE];
101 url = g_strdup_printf(OSRM_DIRECTIONS_STRING,
102 g_ascii_dtostr (startlat, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) start.lat),
103 g_ascii_dtostr (startlon, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) start.lon),
104 g_ascii_dtostr (endlat, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) end.lat),
105 g_ascii_dtostr (endlon, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) end.lon));