Languages

Menu
Sites
Language
GPS Service giving wrong data

I am using given bellow  code to get GPS location in native app.It's working but always given same location which is not my actual postion.

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

 

Sample Code:

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, "%f %f", latitude, longitude);

}
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, "%f %f", latitude, longitude);

}
static location_service_state_e service_state;
static void __state_changed_cb(location_service_state_e state, void *user_data)
{
    service_state = state;  

   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);
}

Looking for help....

Responses

6 Replies
Marco Buettner

device?

Vikram

Strange!!! I works fine for me, i am user the Tizen Z1.

Additional, it's need the location privilege <privilege>http://tizen.org/privilege/location</privilege>

Also, you can try to move you device to check wheter the position will be changed.

A.T.M. Alaul Haque

Mr. Vikram,

I am also using Tizen Z1 device. When I start app it's may always showing default position...

altitude: 37.800000

latitude: 37.253665

longitude: 127.054953

I also added...

    <privileges>
        <privilege>http://tizen.org/privilege/location</privilege>
        <privilege>http://tizen.org/privilege/internet</privilege>
    </privileges>
    <feature name="http://tizen.org/feature/location">true</feature>
    <feature name="http://tizen.org/feature/location.gps">true</feature>

 

Jean Yang

hi, 

 

Do you check if the __state_changed_cb really worked? maybe add some debug info to check this first is helpful

static void __state_changed_cb(location_service_state_e state, void *user_data)
{
    service_state = state;  

   dlog_print(DLOG_INFO, LOG_TAG, " __state_changed_cb");

   get_current_location((appdata_s*)user_data);

}

A.T.M. Alaul Haque

Mr. Jean Yang,

Here I used a dlog_print and getting position_updated data...but when I used a dlog_print under __state_changed_cb it didn't given any debug info

 

    int ret = location_manager_create(LOCATIONS_METHOD_HYBRID, &ad->manager);
    int res = location_manager_set_service_state_changed_cb(ad->manager, __state_changed_cb, (void*)ad);
    if(res!=LOCATIONS_ERROR_NONE)
    {
        dlog_print(DLOG_ERROR, LOG_TAG, "__state_changed_cb failed");
    }
else{
        dlog_print(DLOG_ERROR, LOG_TAG, "__state_changed_cb ok");
        location_manager_set_position_updated_cb(ad->manager, position_updated, 5, (void*)ad);
        ret = location_manager_start(ad->manager);
    }

How can I fix this issue.

Md Imtiaz Hossain

Hi,

Hi,

Please add follwing code to __state_changed_cb

static void __state_changed_cb(location_service_state_e state, void *user_data)
{
    if ( LOCATIONS_SERVICE_ENABLED  == state) {

          dlog_print(DLOG_INFO, LOG_TAG, "Location Service enabled");

    } else {

         dlog_print(DLOG_INFO, LOG_TAG, "Location Service not enabled");

   }

   get_current_location((appdata_s*)user_data);

}

 

That will make sure if your location service is activated or not. You can also details about location_service_state_e from :

https://developer.tizen.org/dev-guide/2.3.0/org.tizen.native.mobile.apireference/group__CAPI__LOCATION__MANAGER__MODULE.html#gad4df3688e5b12625b7ef044a13a50370