How to Get Latitude and Longitude from User Click on Map in Tizen Native App

Original Created Nov 25, 2017 | Regeneration Apr 22, 2026

I'm working on a Tizen native application where I need to:

  1. Display a map
  2. Allow users to drop pins by clicking on the map
  3. Retrieve the latitude and longitude coordinates of the clicked location

I've successfully created a basic map using the following code:

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, 14);
evas_object_show(ad->map);
elm_map_region_show(ad->map, 72.866041, 21.229097);
elm_object_content_set(ad->conform, ad->map);

Elm_Map_Overlay *ovl = elm_map_overlay_add(ad->map, 72.866041, 21.229097);
elm_map_overlay_displayed_zoom_min_set(ovl, 8);
Evas_Object *icon = elm_icon_add(ad->map);
elm_icon_standard_set(icon, "home");
elm_map_overlay_icon_set(ovl, icon);
evas_object_smart_callback_add(ad->map, "clicked", _map_clicked_cb, ad);

Currently, I'm using static coordinates (72.866041, 21.229097). My challenges are:

  1. How to get the current location first
  2. How to retrieve the latitude and longitude when a user clicks on the map to drop a pin

I'm using Tizen Studio 2.0 and Mapzen maps (I already have a Mapzen API key).

Problem Understanding

The user needs to:

  1. Display a map in a Tizen native application
  2. Capture user clicks on the map to drop pins
  3. Retrieve the geographic coordinates (latitude/longitude) of the clicked location

Solution Methods

  1. Using Mapzen Maps:

    • First, set up Mapzen maps with your API key
    • Use the elm_map_canvas_to_region_convert() function to convert canvas coordinates to geographic coordinates when the user clicks
  2. Complete Solution:

    • In your click callback function (_map_clicked_cb), use the following approach:
    static void
    _map_clicked_cb(void *data, Evas_Object *obj, void *event_info)
    {
        Evas_Event_Mouse_Down *ev = event_info;
        double latitude, longitude;
    
        // Convert canvas coordinates to geographic coordinates
        elm_map_canvas_to_region_convert(obj, ev->canvas.x, ev->canvas.y, &latitude, &longitude);
    
        // Now you have the latitude and longitude of the clicked location
        // You can add a pin/marker at this location
        Elm_Map_Overlay *pin = elm_map_overlay_add(obj, latitude, longitude);
        // Configure your pin as needed
    }
    
  3. Reverse Geocoding:

    • Once you have the coordinates, you can use Mapzen's reverse geocoding API to get address information:
    // Use the latitude and longitude to make a reverse geocoding request
    // to Mapzen's API (https://mapzen.com/documentation/search/reverse/)
    

Code Examples

Here's a complete example for handling map clicks:

// Add this to your map creation code
evas_object_smart_callback_add(ad->map, "clicked", _map_clicked_cb, ad);

// Click callback implementation
static void
_map_clicked_cb(void *data, Evas_Object *obj, void *event_info)
{
    AppData *ad = data;
    Evas_Event_Mouse_Down *ev = event_info;
    double lat, lon;
    
    // Convert click coordinates to geographic coordinates
    elm_map_canvas_to_region_convert(obj, ev->canvas.x, ev->canvas.y, &lat, &lon);
    
    // Add a pin at the clicked location
    Elm_Map_Overlay *pin = elm_map_overlay_add(obj, lat, lon);
    Evas_Object *icon = elm_icon_add(obj);
    elm_icon_standard_set(icon, "location");
    elm_map_overlay_icon_set(pin, icon);
    
    // Store or use the coordinates as needed
    printf("Clicked at: %f, %f\n", lat, lon);
}

Additional Tips

  1. Make sure you have proper permissions in your manifest file:
    <privileges>
        <privilege>http://tizen.org/privilege/mapservice</privilege>
        <privilege>http://tizen.org/privilege/internet</privilege>
    </privileges>
    
  2. For current location, consider using the Location Manager API
  3. Remember that Mapzen services might have usage limits based on your API key

Customize your cookie preferences

You can enable or disable non-essential cookies. Essential cookies are always on to ensure the site works properly and to keep you signed in.

Necessary

These cookies are necessary for the website to function properly and cannot be switched off. They help with things like logging in and setting your privacy preferences.

Always on

Analytics

These cookies help us improve the site by tracking which pages are most popular and how visitors move around the site.

Enable analytics cookies
Public Forum Public Forum
Employees only. Please sign in with your company account.