summaryrefslogtreecommitdiff
path: root/src/here/here_utils.cpp
blob: 9cc2c47d616c3e2127f94f696c557d1180644c57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "here_utils.h"


static const double LATITUDE_RANGE = 85.05113;
static const double LONGITUDE_RANGE = 180.0;


extern "C"
{
int ConvertToMapsError(int nErr)
{
	switch (nErr)
	{
		case HERE_ERROR_NONE:                  return MAPS_ERROR_NONE;
		case HERE_ERROR_PERMISSION_DENIED:     return MAPS_ERROR_PERMISSION_DENIED;
		case HERE_ERROR_OUT_OF_MEMORY:         return MAPS_ERROR_OUT_OF_MEMORY;
		case HERE_ERROR_INVALID_PARAMETER:     return MAPS_ERROR_INVALID_PARAMETER;
		case HERE_ERROR_NOT_SUPPORTED:         return MAPS_ERROR_NOT_SUPPORTED;
		case HERE_ERROR_CONNECTION_TIME_OUT:   return MAPS_ERROR_CONNECTION_TIME_OUT;
		case HERE_ERROR_NETWORK_UNREACHABLE:   return MAPS_ERROR_NETWORK_UNREACHABLE;
		case HERE_ERROR_INVALID_OPERATION:     return MAPS_ERROR_INVALID_OPERATION;
		case HERE_ERROR_KEY_NOT_AVAILABLE:     return MAPS_ERROR_KEY_NOT_AVAILABLE;
		case HERE_ERROR_RESOURCE_BUSY:         return MAPS_ERROR_RESOURCE_BUSY;
		case HERE_ERROR_CANCELED:              return MAPS_ERROR_CANCELED;
		case HERE_ERROR_UNKNOWN:               return MAPS_ERROR_UNKNOWN;
		case HERE_ERROR_SERVICE_NOT_AVAILABLE: return MAPS_ERROR_SERVICE_NOT_AVAILABLE;
		case HERE_ERROR_NOT_FOUND:             return MAPS_ERROR_NOT_FOUND;
	}
	return MAPS_ERROR_UNKNOWN;
}

int ConvertToHereError(int nErr)
{
	switch (nErr)
	{
		case MAPS_ERROR_NONE:                  return HERE_ERROR_NONE;
		case MAPS_ERROR_PERMISSION_DENIED:     return HERE_ERROR_PERMISSION_DENIED;
		case MAPS_ERROR_OUT_OF_MEMORY:         return HERE_ERROR_OUT_OF_MEMORY;
		case MAPS_ERROR_INVALID_PARAMETER:     return HERE_ERROR_INVALID_PARAMETER;
		case MAPS_ERROR_NOT_SUPPORTED:         return HERE_ERROR_NOT_SUPPORTED;
		case MAPS_ERROR_CONNECTION_TIME_OUT:   return HERE_ERROR_CONNECTION_TIME_OUT;
		case MAPS_ERROR_NETWORK_UNREACHABLE:   return HERE_ERROR_NETWORK_UNREACHABLE;
		case MAPS_ERROR_INVALID_OPERATION:     return HERE_ERROR_INVALID_OPERATION;
		case MAPS_ERROR_KEY_NOT_AVAILABLE:     return HERE_ERROR_KEY_NOT_AVAILABLE;
		case MAPS_ERROR_RESOURCE_BUSY:         return HERE_ERROR_RESOURCE_BUSY;
		case MAPS_ERROR_CANCELED:              return HERE_ERROR_CANCELED;
		case MAPS_ERROR_UNKNOWN:               return HERE_ERROR_UNKNOWN;
		case MAPS_ERROR_SERVICE_NOT_AVAILABLE: return HERE_ERROR_SERVICE_NOT_AVAILABLE;
		case MAPS_ERROR_NOT_FOUND:             return HERE_ERROR_NOT_FOUND;
	}
	return HERE_ERROR_UNKNOWN;
}
}


HERE_PLUGIN_BEGIN_NAMESPACE

HereUtils::HereUtils()
{
}

HereUtils::~HereUtils()
{
}

GeoRouteQuery::TravelMode HereUtils::Convert(maps_route_transport_mode_e nVal)
{
	switch (nVal)
	{
		case MAPS_ROUTE_TRANSPORT_MODE_CAR:           return GeoRouteQuery::TM_CarTravel;
		case MAPS_ROUTE_TRANSPORT_MODE_PEDESTRIAN:    return GeoRouteQuery::TM_PedestrianTravel;
		case MAPS_ROUTE_TRANSPORT_MODE_PUBLICTRANSIT: return GeoRouteQuery::TM_PublicTransitTravel;
		default: break;
	}
	return GeoRouteQuery::TM_CarTravel;
}

maps_route_transport_mode_e HereUtils::Convert(GeoRouteQuery::TravelMode nVal)
{
	switch (nVal)
	{
		case GeoRouteQuery::TM_CarTravel:           return MAPS_ROUTE_TRANSPORT_MODE_CAR;
		case GeoRouteQuery::TM_PedestrianTravel:    return MAPS_ROUTE_TRANSPORT_MODE_PEDESTRIAN;
		case GeoRouteQuery::TM_PublicTransitTravel: return MAPS_ROUTE_TRANSPORT_MODE_PUBLICTRANSIT;
		default: break;
	}
	return MAPS_ROUTE_TRANSPORT_MODE_CAR;
}

GeoRouteQuery::FeatureType HereUtils::Convert(maps_route_feature_e nVal)
{
	switch (nVal)
	{
		case MAPS_ROUTE_FEATURE_NO:             return GeoRouteQuery::FT_NoFeature;
		case MAPS_ROUTE_FEATURE_TOLL:           return GeoRouteQuery::FT_TollFeature;
		case MAPS_ROUTE_FEATURE_MOTORWAY:       return GeoRouteQuery::FT_MotorwayFeature;
		case MAPS_ROUTE_FEATURE_BOATFERRY:      return GeoRouteQuery::FT_BoatFerryFeature;
		case MAPS_ROUTE_FEATURE_RAILFERRY:      return GeoRouteQuery::FT_RailFerryFeature;
		case MAPS_ROUTE_FEATURE_PUBLICTTRANSIT: return GeoRouteQuery::FT_PublicTransitFeature;
		case MAPS_ROUTE_FEATURE_TUNNEL:         return GeoRouteQuery::FT_TunnelFeature;
		case MAPS_ROUTE_FEATURE_DIRTROAD:       return GeoRouteQuery::FT_DirtRoadFeature;
		case MAPS_ROUTE_FEATURE_PARKS:          return GeoRouteQuery::FT_ParksFeature;
		case MAPS_ROUTE_FEATURE_HOVLANE:        return GeoRouteQuery::FT_HOVLane;
		case MAPS_ROUTE_FEATURE_STAIRS:         return GeoRouteQuery::FT_Stairs;
		default: break;
	}
	return GeoRouteQuery::FT_NoFeature;
}

GeoRouteQuery::FeatureWeight HereUtils::Convert(maps_route_feature_weight_e nVal)
{
	switch (nVal)
	{
		case MAPS_ROUTE_FEATURE_WEIGHT_NORMAL:        return GeoRouteQuery::FW_NormalFeatureWeight;
		case MAPS_ROUTE_FEATURE_WEIGHT_PREFER:        return GeoRouteQuery::FW_PreferFeatureWeight;
		case MAPS_ROUTE_FEATURE_WEIGHT_AVOID:         return GeoRouteQuery::FW_AvoidFeatureWeight;
		case MAPS_ROUTE_FEATURE_WEIGHT_SOFTEXCLUDE:   return GeoRouteQuery::FW_SoftExcludeFeatureWeight;
		case MAPS_ROUTE_FEATURE_WEIGHT_STRICTEXCLUDE: return GeoRouteQuery::FW_StrictExcludeFeatureWeight;
		default: break;
	}
	return GeoRouteQuery::FW_NormalFeatureWeight;
}

maps_route_turn_type_e HereUtils::Convert(Maneuver::InstructionDirection nVal)
{
	switch (nVal)
	{
		case Maneuver::ID_NoDirection:          return MAPS_ROUTE_TURN_TYPE_NONE;
		case Maneuver::ID_DirectionForward:     return MAPS_ROUTE_TURN_TYPE_STRAIGHT;
		case Maneuver::ID_DirectionBearRight:   return MAPS_ROUTE_TURN_TYPE_BEAR_RIGHT;
		case Maneuver::ID_DirectionLightRight:  return MAPS_ROUTE_TURN_TYPE_LIGHT_RIGHT;
		case Maneuver::ID_DirectionRight:       return MAPS_ROUTE_TURN_TYPE_RIGHT;
		case Maneuver::ID_DirectionHardRight:   return MAPS_ROUTE_TURN_TYPE_HARD_RIGHT;
		case Maneuver::ID_DirectionUTurnRight:  return MAPS_ROUTE_TURN_TYPE_UTURN_RIGHT;
		case Maneuver::ID_DirectionUTurnLeft:   return MAPS_ROUTE_TURN_TYPE_UTURN_LEFT;
		case Maneuver::ID_DirectionHardLeft:    return MAPS_ROUTE_TURN_TYPE_HARD_LEFT;
		case Maneuver::ID_DirectionLeft:        return MAPS_ROUTE_TURN_TYPE_LEFT;
		case Maneuver::ID_DirectionLightLeft:   return MAPS_ROUTE_TURN_TYPE_LIGHT_LEFT;
		case Maneuver::ID_DirectionBearLeft:    return MAPS_ROUTE_TURN_TYPE_BEAR_LEFT;
		default: break;
	}
	return MAPS_ROUTE_TURN_TYPE_NONE;
}

Maneuver::InstructionDirection HereUtils::Convert(maps_route_turn_type_e nVal)
{
	switch (nVal)
	{
		case MAPS_ROUTE_TURN_TYPE_NONE:         return Maneuver::ID_NoDirection;
		case MAPS_ROUTE_TURN_TYPE_STRAIGHT:     return Maneuver::ID_DirectionForward;
		case MAPS_ROUTE_TURN_TYPE_BEAR_RIGHT:   return Maneuver::ID_DirectionBearRight;
		case MAPS_ROUTE_TURN_TYPE_LIGHT_RIGHT:  return Maneuver::ID_DirectionLightRight;
		case MAPS_ROUTE_TURN_TYPE_RIGHT:        return Maneuver::ID_DirectionRight;
		case MAPS_ROUTE_TURN_TYPE_HARD_RIGHT:   return Maneuver::ID_DirectionHardRight;
		case MAPS_ROUTE_TURN_TYPE_UTURN_RIGHT:  return Maneuver::ID_DirectionUTurnRight;
		case MAPS_ROUTE_TURN_TYPE_UTURN_LEFT:   return Maneuver::ID_DirectionUTurnLeft;
		case MAPS_ROUTE_TURN_TYPE_HARD_LEFT:    return Maneuver::ID_DirectionHardLeft;
		case MAPS_ROUTE_TURN_TYPE_LEFT:         return Maneuver::ID_DirectionLeft;
		case MAPS_ROUTE_TURN_TYPE_LIGHT_LEFT:   return Maneuver::ID_DirectionLightLeft;
		case MAPS_ROUTE_TURN_TYPE_BEAR_LEFT:    return Maneuver::ID_DirectionBearLeft;
		default: break;
	}
	return Maneuver::ID_NoDirection;
}

GeoBoundingBox& HereUtils::Convert(maps_area_h hArea, GeoBoundingBox& Box)
{
	maps_area_s* area_s = (maps_area_s*)hArea;

	if (!area_s || area_s->type != MAPS_AREA_RECTANGLE) return Box;

	GeoCoordinates hereCoordLT(area_s->rect.top_left.latitude, area_s->rect.top_left.longitude);
	GeoCoordinates hereCoordRB(area_s->rect.bottom_right.latitude, area_s->rect.bottom_right.longitude);

	Box.SetTopLeft(hereCoordLT);
	Box.SetBottomRight(hereCoordRB);

	return Box;
}

maps_area_h& HereUtils::Convert(GeoBoundingBox Box, maps_area_h& hArea)
{
	maps_coordinates_h mapsCoordLT, mapsCoordRB;
	GeoCoordinates hereCoordLT, hereCoordRB;

	hereCoordLT = Box.GetTopLeft();
	hereCoordRB = Box.GetBottomRight();

	maps_coordinates_create(hereCoordLT.GetLatitude(), hereCoordLT.GetLongitude(), &mapsCoordLT);
	maps_coordinates_create(hereCoordRB.GetLatitude(), hereCoordRB.GetLongitude(), &mapsCoordRB);

	maps_area_create_rectangle(mapsCoordLT, mapsCoordRB, &hArea);

	maps_coordinates_destroy(mapsCoordLT);
	maps_coordinates_destroy(mapsCoordRB);

	return hArea;
}

void HereUtils::Convert(String strUtf8, WString& strUtf16)
{
	strUtf16.assign(strUtf8.begin(), strUtf8.end());
}

void HereUtils::Convert(WString strUtf16, String& strUtf8)
{
	strUtf8.assign(strUtf16.begin(), strUtf16.end());
}

GeoBoundingBox& HereUtils::Convert(const char *src, GeoBoundingBox &box)
{
	int i = 0;
	char *token, *next;
	double coord[4] = { 0.0, };

	token = strtok_r((char*)src, ",;", &next);
	while (token && i < 4)
	{
		coord[i++] = atof(token);
		token = strtok_r(NULL, ",;", &next);
	}
	box.SetTopLeft(GeoCoordinates(coord[0], coord[1]));
	box.SetBottomRight(GeoCoordinates(coord[2], coord[3]));
	return box;
}

bool HereUtils::IsValid(GeoCoordinates geoCoord)
{
	return IsValidCoord(geoCoord.GetLatitude(), geoCoord.GetLongitude());
}

bool HereUtils::IsValid(maps_coordinates_s geoCoord)
{
	return IsValidCoord(geoCoord.latitude, geoCoord.longitude);
}

bool HereUtils::IsValidCoord(double dLat, double dLng)
{
	return ((dLat <= LATITUDE_RANGE && dLat >= -LATITUDE_RANGE) &&
		(dLng <= LONGITUDE_RANGE && dLng >= -LONGITUDE_RANGE));
}

bool HereUtils::IsValid(maps_area_s hArea)
{
	if (hArea.type == MAPS_AREA_RECTANGLE)
	{
		return (HereUtils::IsValid(hArea.rect.top_left) &&
			HereUtils::IsValid(hArea.rect.bottom_right));
	}
	else if(hArea.type == MAPS_AREA_CIRCLE)
	{
		return HereUtils::IsValid(hArea.circle.center);
	}
	else
		return false;
}


HERE_PLUGIN_END_NAMESPACE