4 * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
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>
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
27 #include "gps_manager_data_types.h"
28 #include "last_position.h"
29 #include "debug_util.h"
32 static void gps_manager_set_last_position(last_pos_t * last_pos)
34 LOG_GPS(DBG_LOW, "set Last Latitude = %f Longitude = %f Altitude = %f H_Accuracy = %f V_Accuracy = %f",
35 last_pos->latitude, last_pos->longitude, last_pos->altitude, last_pos->hor_accuracy, last_pos->ver_accuracy);
37 setting_set_int(LAST_TIMESTAMP, last_pos->timestamp);
38 setting_set_double(LAST_LATITUDE, last_pos->latitude);
39 setting_set_double(LAST_LONGITUDE, last_pos->longitude);
40 setting_set_double(LAST_ALTITUDE, last_pos->altitude);
41 setting_set_double(LAST_HOR_ACCURACY, last_pos->hor_accuracy);
42 setting_set_double(LAST_VER_ACCURACY, last_pos->ver_accuracy);
45 double deg2rad(double deg)
47 return (deg * M_PI / 180);
50 void gps_manager_get_last_position(last_pos_t * last_pos)
52 setting_get_int(LAST_TIMESTAMP, &last_pos->timestamp);
53 setting_get_double(LAST_LATITUDE, &last_pos->latitude);
54 setting_get_double(LAST_LONGITUDE, &last_pos->longitude);
55 setting_get_double(LAST_ALTITUDE, &last_pos->altitude);
56 setting_get_double(LAST_HOR_ACCURACY, &last_pos->hor_accuracy);
57 setting_get_double(LAST_VER_ACCURACY, &last_pos->ver_accuracy);
59 LOG_GPS(DBG_LOW, "get Last Latitude = %f Longitude = %f Altitude = %f H_Accuracy = %f V_Accuracy = %f",
60 last_pos->latitude, last_pos->longitude, last_pos->altitude, last_pos->hor_accuracy, last_pos->ver_accuracy);
63 int gps_manager_distance_to_last_position(const pos_data_t * pos, const last_pos_t * last_pos)
65 double delta_lat, delta_long;
68 delta_lat = pos->latitude - last_pos->latitude;
69 delta_long = pos->longitude - last_pos->longitude;
71 dist = sin(deg2rad(delta_lat) / 2) * sin(deg2rad(delta_lat) / 2) +
72 cos(deg2rad(pos->latitude)) * cos(deg2rad(last_pos->latitude)) *
73 sin(deg2rad(delta_long) / 2) * sin(deg2rad(delta_long) / 2);
74 dist = 2 * atan2(sqrt(dist), sqrt(1 - dist));
75 dist = 6371 * dist; // unit: 'km'
84 void gps_manager_update_last_position(const pos_data_t * pos, last_pos_t * last_pos)
86 last_pos->timestamp = pos->timestamp;
87 last_pos->latitude = pos->latitude;
88 last_pos->longitude = pos->longitude;
89 last_pos->altitude = pos->altitude;
90 last_pos->hor_accuracy = pos->hor_accuracy;
91 last_pos->ver_accuracy = pos->ver_accuracy;
93 gps_manager_set_last_position(last_pos);