Languages

Menu
Sites
Language
GPS Service Not Available

Hi All,

I am using Tizen 2.3.0_Rev2 SDK.

I am developing an Application for Samsung Z1 mobile where I need gps location.

when I try to get the position from API (location_manager_get_location) it says LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE

     ret = location_manager_get_location(manager, &altitude, &latitude, &longitude,
                                             &climb, &direction, &speed, &level, &horizontal, &vertical, &timestamp);
    if(LOCATIONS_ERROR_NONE != ret){
        ERR("location_manager_get_location() Failed!!. Error Code = %d", ret);
        __print_gps_error(ret);
        return false;
    }

My GPS already enabled. Also creating location manager and starting location service is not returing any error.

Please help if anybody faced this issue earlier.

Thank you.

View Selected Answer

Responses

4 Replies
colin Rao

Did you include the location privilege in your manifest xml file?

Mark as answer
colin Rao

I  can get the gps location success, share the sample code here.

include #include <locations.h>,

and add location privilege in manifest,

<privilege>http://tizen.org/privilege/location</privilege>

static void
get_current_location(appdata_s *ad)
{
    double altitude, latitude, longitude, climb, direction, speed;
    double horizontal, vertical;
	location_accuracy_level_e level;
	time_t timestamp;

	int ret = location_manager_get_location(ad->manager, &altitude, &latitude, &longitude, &climb, &direction, &speed, &level, &horizontal, &vertical, &timestamp);
	dlog_print(DLOG_INFO, LOG_TAG, "get current location success? %s", ret == 0 ? "Yes" : "No");

	Eina_Strbuf *strbuf = eina_strbuf_new();
	eina_strbuf_append_printf(strbuf,
			    "altitude: %f <br/>latitude: %f <br/>longitude: %f <br/>climb: %f<br/>direction: %f <br/>speed: %f <br/>level: %f <br/>horizontal: %f <br/>vertical: %f <br/>timestamp: %lf",
			    altitude, latitude, longitude, climb, direction, speed, level, horizontal, vertical, timestamp);
	char *gps_info = eina_strbuf_string_steal(strbuf);
    elm_object_text_set(ad->gps_lable, gps_info);

    dlog_print(DLOG_INFO, LOG_TAG, "%s", gps_info);

    eina_strbuf_free(strbuf);
    free(gps_info);
}
static void
position_updated(double latitude, double longitude, double altitude, time_t timestamp, void *user_data)
{
	appdata_s *ad = (appdata_s*)user_data;

	dlog_print(DLOG_INFO, LOG_TAG, "position_updated");

	Eina_Strbuf *strbuf = eina_strbuf_new();
	eina_strbuf_append_printf(strbuf,
			    "altitude: %f <br/>latitude: %f <br/>longitude: %f <br/>timestamp: %lf",
			    altitude, latitude, longitude, timestamp);
	char *gps_info = eina_strbuf_string_steal(strbuf);
    elm_object_text_set(ad->gps_lable, gps_info);

    dlog_print(DLOG_INFO, LOG_TAG, "%s", gps_info);

    eina_strbuf_free(strbuf);
    free(gps_info);
}
static location_service_state_e service_state;
static void
__state_changed_cb(location_service_state_e state, void *user_data)
{
    service_state = state;
    dlog_print(DLOG_INFO, LOG_TAG, "service_state: %s", state == 0 ? "LOCATIONS_SERVICE_DISABLED" : "LOCATIONS_SERVICE_ENABLED");

    if(state != LOCATIONS_SERVICE_ENABLED)
    	return;

    get_current_location((appdata_s*)user_data);
}
static void
start_location_manager(appdata_s *ad)
{
	int ret = location_manager_create(LOCATIONS_METHOD_GPS, &ad->manager);
	ret = location_manager_set_service_state_changed_cb(ad->manager, __state_changed_cb, (void*)ad);
	location_manager_set_position_updated_cb(ad->manager, position_updated, 2, (void*)ad);
	ret = location_manager_start(ad->manager);
}

 

Dharmesh Guna

Hi Colin,

Thanks for update.

Yes I lerned latter about asynchronous callbacks.

So once settalite details are fetched then only we are able to call APIs to fetch location details.

After creating a sample app I am successfully able to get the location details.
 

A.T.M. Alaul Haque

Hi Colin,

Thanks for your suggestion.

I also using your code but it's always given the same data.like....

altitude: 37.800000

latitude: 37.253665

longitude: 127.054953

...which is note my actual position.

 

My actual lat long position is...

latitude: 23.7489959

longitude:90.3917064

 

Looking for your help.