Updating location periodically on a map

Updating location periodically on a map
#include <locations.h>


#define LOG_TAG "Location"

location_manager_h locationmanager = NULL;
Evas_Object *map;
Elm_Map_Overlay *overlay = NULL;


void overlay_state_set(bool state)
{
	if(state == TRUE)
	   elm_map_overlay_color_set(overlay, 0x00, 0xfa, 0x9a, 0xff); // Green color overlay in connected state
	else
	   elm_map_overlay_color_set(overlay, 0xff, 0x00, 0x00, 0xff); // Red color overlay in disconnected state
}


static void map_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
	if(locationmanager != NULL)
	{
		location_manager_unset_service_state_changed_cb(locationmanager);
		location_manager_unset_position_updated_cb(locationmanager);
		location_manager_stop(locationmanager);
		location_manager_destroy(locationmanager);

		locationmanager = NULL;
	}
}


static void position_updated_cb(double latitude, double longitude, double altitude, time_t timestamp, void *user_data)
{
	elm_map_region_bring_in(map, longitude, latitude);

// previous overlay should be deleted in order to prevent showing multiple overlays on the map
	if(overlay != NULL)
		elm_map_overlay_del(overlay);

	overlay = elm_map_overlay_add(map, longitude, latitude);
	overlay_state_set(TRUE);
}


static void state_changed_cb(location_service_state_e state, void *user_data)
{
	int location_request_status = -1;

	switch(state){
	case LOCATIONS_SERVICE_DISABLED :
		overlay_state_set(FALSE);

		break;
		
// register position update callback with 10secs period once a device connects to location service
	case LOCATIONS_SERVICE_ENABLED :
        location_manager_set_position_updated_cb(locationmanager, position_updated_cb, 10, NULL);
        
        break;
}


void get_location(void *data)
{
	bool result = FALSE;
	int location_request_status = -1;

    location_manager_is_supported_method(LOCATIONS_METHOD_HYBRID);

	location_manager_create(LOCATIONS_METHOD_HYBRID, &locationmanager);
	location_manager_set_service_state_changed_cb(locationmanager, state_changed_cb, NULL);
    location_manager_start(locationmanager);

    double altitude, latitude, longitude;
    time_t timestamp;

    location_manager_get_last_position(locationmanager, &altitude, &latitude, &longitude, &timestamp);

// shows last postion on the map as soon as app is started
    elm_map_region_bring_in(map, longitude, latitude);

	overlay = elm_map_overlay_add(map, longitude, latitude);

// map overlay color is shown red until GPS or WPS update location information
	overlay_state_set(FALSE);
}


static void
create_base_gui(appdata_s *ad)
{
.
.
.

	map = elm_map_add(ad->naviframe);

	elm_map_zoom_set(map, 15);

	get_location(data);

	elm_naviframe_item_push(nf, "Map", NULL, NULL, map, "empty");

	evas_object_event_callback_add(map, EVAS_CALLBACK_DEL , map_del_cb, NULL);

.
.
.

}
.
.
.

Responses

0 Replies