13560f6111762f9874a610c8608456db59e8fc9a
[platform/core/location/location-module.git] / modules / osm / osm-route-yours.c
1 /*
2  * location-module
3  *
4  * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7  *          Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 //http://www.yournavigation.org/api/1.0/gosmore.php?format=geojson&flat=52.215676&flon=5.963946&tlat=52.2573&tlon=6.1799&v=motorcar&fast=1&layer=mapnik
23 //http://www.yournavigation.org/api/1.0/gosmore.php?formats=geojson/&flat=52.215676&flot=5.963946&tlat=52.257300&tlon=6.179900&v=carmotor&fast=1&instructions=1&layer=mapnik
24 //http://www.yournavigation.org/api/1.0/gosmore.php?format=geojson&flat=52.215676&flon=5.963946&tlat=52.2573&tlon=6.179900&v=motorcar&fast=1&instructions=1&layer=mapnik
25
26 #include <location.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include "log.h"
30
31 const char *YOURS_SERVER = "http://www.yournavigation.org/api/1.0/gosmore.php?";
32 const char *YOURS_FORMAT = "format=";
33 const char *YOURS_INSTRUCTIONS = "instructions=";
34 const char *YOURS_TYPE = "v=";
35 const char *YOURS_FAST = "fast=";
36 const char *YOURS_END = "layer=mapnik";
37
38 const char *YOURS_FORMAT_KML = "kml";
39 const char *YOURS_FORMAT_GEOJSON = "geojson";
40
41 const char *YOURS_SET_ON = "1";
42 const char *YOURS_SET_OFF = "0";
43
44 const char delimeter = '&';
45
46 static int _add_option (char *buf, const char *key, const char *option)
47 {
48         if (!buf || !option) return -1;
49
50         if (strlen(buf) == 0) { //create
51                 strncpy(buf, YOURS_SERVER, strlen (YOURS_SERVER));
52
53                 if (key) strncat(buf, key, strlen (key));
54                 strncat(buf, option, strlen (option));
55
56         } else {
57                 strncat(buf, &delimeter, 1);
58                 if (key) strncat(buf, key, strlen (key));
59                 strncat(buf, option, strlen (option));
60         }
61
62         return 0;
63 }
64
65 char* yournavi_create_url (gdouble flat, gdouble flon, gdouble tlat, gdouble tlon, GList *way, int type, char *mode ,int instruction)
66 {
67         char url[1024] = {0, };
68         char pos_str[64] = {0, };
69
70         //TODO WAYPOINT : Not supported
71
72
73 #if 0   // kml
74         _add_option(url, YOURS_FORMAT, YOURS_FORMAT_KML);
75 #else
76         _add_option(url, YOURS_FORMAT, YOURS_FORMAT_GEOJSON);
77 #endif
78
79         snprintf(pos_str, 64, "flat=%f&flot=%f&tlat=%f&tlon=%f", flat, flon, tlat, tlon);
80         _add_option (url, NULL, pos_str);
81
82         _add_option (url, YOURS_TYPE, mode);
83
84         if (type)
85                 _add_option (url, YOURS_FAST, YOURS_SET_ON);
86         else
87                 _add_option (url, YOURS_FAST, YOURS_SET_OFF);
88
89         if (instruction)
90                 _add_option (url, YOURS_INSTRUCTIONS, YOURS_SET_ON);
91
92         _add_option (url, NULL, YOURS_END);
93
94         MOD_LOGW ("URL[%s]", url);
95
96         return g_strdup(url);
97 }
98