How to get current GPS location and show it on map by GPS service and map widget

This sample code describes how to start the location manager and get the device’s GPS position info.
// Create map widget
ad->map = elm_map_add(ad->conform);
evas_object_size_hint_weight_set(ad->map, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(ad->map, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_map_zoom_mode_set(ad->map, ELM_MAP_ZOOM_MODE_MANUAL);
elm_map_zoom_set(ad->map, 13);
evas_object_show(ad->map);
elm_object_content_set(ad->conform, ad->map);

// Start gps service
location_manager_create(LOCATIONS_METHOD_GPS, &ad->gps);
location_manager_set_service_state_changed_cb(ad->gps, __state_changed_cb, (void*)ad);
location_manager_start(ad->gps);

// __state_changed_cb, get current gps position and add an icon overlay on the map widget
static void__state_changed_cb(location_service_state_e state, void *user_data)
{
    appdata_s *ad = (appdata_s*)user_data;
    double altitude, latitude, longitude, climb, direction, speed, horizontal, vertical;
    location_accuracy_level_e level;
        time_t timestamp;

    if(state == LOCATIONS_SERVICE_ENABLED) 
    {
        location_manager_get_location(ad->gps, &altitude, &latitude, &longitude, &climb, &direction, &speed, &level, &horizontal, &vertical, &timestamp);
        elm_map_region_bring_in(ad->map, longitude, latitude);
        // add an position icon overlay on the map
        Elm_Map_Overlay *ovl = elm_map_overlay_add(ad->map, longitude, latitude);
        elm_map_overlay_displayed_zoom_min_set(ovl, 8);
        Evas_Object *icon = elm_icon_add(ad->map);
        elm_icon_standard_set(icon, ICON_DIR"location_32.png");
        elm_map_overlay_icon_set(ovl, icon);
    }
}

Responses

0 Replies