2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2005-2008, Alex Foobarian <foobarian@gmail.com>
5 * Copyright (C) 2012-2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * SECTION:googlerouting
25 * @short_description: the class for Google Directions
27 * The #GoogleRouting class handles Google Directions
28 * service as routing engine.
30 * Technical details are available here:
31 * https://developers.google.com/maps/documentation/directions/#DirectionsResponses
33 * gpsbabel supports this format.
43 #include <glib/gstdio.h>
45 #include "googlerouting.h"
47 #define GOOGLE_DIRECTIONS_STRING "maps.google.com/maps?q=from:%s,%s+to:%s,%s&output=js"
49 static DownloadMapOptions googles_routing_options = { FALSE, FALSE, "http://maps.google.com/", 0, NULL };
51 static gchar *google_routing_get_url_for_coords ( VikRoutingEngine *self, struct LatLon start, struct LatLon end );
52 static DownloadMapOptions *google_routing_get_download_options ( VikRoutingEngine *self );
54 G_DEFINE_TYPE (GoogleRouting, google_routing, VIK_ROUTING_ENGINE_TYPE)
56 static void google_routing_class_init ( GoogleRoutingClass *klass )
58 GObjectClass *object_class;
59 VikRoutingEngineClass *parent_class;
61 object_class = G_OBJECT_CLASS (klass);
63 parent_class = VIK_ROUTING_ENGINE_CLASS (klass);
65 parent_class->get_url_for_coords = google_routing_get_url_for_coords;
66 parent_class->get_download_options = google_routing_get_download_options;
72 * Create a new instance of GoogleRouting routing engine.
74 GoogleRouting *google_routing_new ()
76 return GOOGLE_ROUTING ( g_object_new ( GOOGLE_ROUTING_TYPE,
83 static void google_routing_init ( GoogleRouting *vlp )
87 static DownloadMapOptions *
88 google_routing_get_download_options ( VikRoutingEngine *self )
90 return &googles_routing_options;
94 * Override VikRoutingEngine:get_download_options()
97 google_routing_get_url_for_coords ( VikRoutingEngine *self, struct LatLon start, struct LatLon end )
99 gchar startlat[G_ASCII_DTOSTR_BUF_SIZE], startlon[G_ASCII_DTOSTR_BUF_SIZE];
100 gchar endlat[G_ASCII_DTOSTR_BUF_SIZE], endlon[G_ASCII_DTOSTR_BUF_SIZE];
102 url = g_strdup_printf(GOOGLE_DIRECTIONS_STRING,
103 g_ascii_dtostr (startlat, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) start.lat),
104 g_ascii_dtostr (startlon, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) start.lon),
105 g_ascii_dtostr (endlat, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) end.lat),
106 g_ascii_dtostr (endlon, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) end.lon));