]> git.street.me.uk Git - andy/viking.git/blob - src/googlerouting.c
Remove uneeded (and wrong) finalize functions
[andy/viking.git] / src / googlerouting.c
1 /*
2  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3  *
4  * Copyright (C) 2005-2008, Alex Foobarian <foobarian@gmail.com>
5  * Copyright (C) 2012-2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
6  *
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.
11  *
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.
16  *
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
20  *
21  */
22
23 /**
24  * SECTION:googlerouting
25  * @short_description: the class for Google Directions
26  * 
27  * The #GoogleRouting class handles Google Directions 
28  * service as routing engine.
29  * 
30  * Technical details are available here:
31  * https://developers.google.com/maps/documentation/directions/#DirectionsResponses
32  *
33  * gpsbabel supports this format.
34  */
35
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 #include <string.h>
41
42 #include <glib.h>
43 #include <glib/gstdio.h>
44
45 #include "googlerouting.h"
46
47 #define GOOGLE_DIRECTIONS_STRING "maps.google.com/maps?q=from:%s,%s+to:%s,%s&output=js"
48
49 static DownloadMapOptions googles_routing_options = { FALSE, FALSE, "http://maps.google.com/", 0, NULL };
50
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 );
53
54 G_DEFINE_TYPE (GoogleRouting, google_routing, VIK_ROUTING_ENGINE_TYPE)
55
56 static void google_routing_class_init ( GoogleRoutingClass *klass )
57 {
58   GObjectClass *object_class;
59   VikRoutingEngineClass *parent_class;
60
61   object_class = G_OBJECT_CLASS (klass);
62
63   parent_class = VIK_ROUTING_ENGINE_CLASS (klass);
64
65   parent_class->get_url_for_coords = google_routing_get_url_for_coords;
66   parent_class->get_download_options = google_routing_get_download_options;
67 }
68
69 /**
70  * google_routing_new:
71  * 
72  * Create a new instance of GoogleRouting routing engine.
73  */
74 GoogleRouting *google_routing_new ()
75 {
76   return GOOGLE_ROUTING ( g_object_new ( GOOGLE_ROUTING_TYPE,
77                                          "id", "google",
78                                          "label", "Google",
79                                          "format", "google",
80                                          NULL ) );
81 }
82
83 static void google_routing_init ( GoogleRouting *vlp )
84 {
85 }
86
87 static DownloadMapOptions *
88 google_routing_get_download_options ( VikRoutingEngine *self )
89 {
90         return &googles_routing_options;
91 }
92
93 /*
94  * Override VikRoutingEngine:get_download_options()
95  */
96 gchar *
97 google_routing_get_url_for_coords ( VikRoutingEngine *self, struct LatLon start, struct LatLon end )
98 {
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];
101     gchar *url;
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));
107
108     return url;
109 }