How to Use the Tizen Native Reverse Geocode API in 3 Steps

Since Tizen 2.4

What is Reverse Geocoding?

Reverse Geocoding translates the geographical coordinates of a place into an address.

The Reverse Geocode API is one of the Maps Services provided by the Tizen Native Location Framework.

Tizen Native Maps Service API

To start using the Reverse Geocode API:

  1. Create an empty Tizen native application.
  2. Start the Maps Service.
  3. Run a reverse geocode request.

Prerequisites

This document assumes that you already have basic knowledge in Tizen development. For basic information, see https://developer.tizen.org/development/getting-started/preface.

The Maps Service API requires a security key issued by the maps provider.
In case of HERE maps, the security key is a concatenation of app_id and app_code, generated on https://developer.here.com/plans/api/consumer-mapping according to your consumer plan.

“your-security-key” is “app_id/app_code”
Note Make sure your device or emulator has a valid internet connection.

To ensure the Maps Services API execution, set the following privileges:

  • http://tizen.org/privilege/mapservice
  • http://tizen.org/privilege/internet
  • http://tizen.org/privilege/network.get

Set Privileges

1 Create an Empty Tizen Native Application

In the IDE, create an empty application using the basic UI application template, and run it on an emulator or a device.

Create Empty Tizen Native Project

The "Hello Tizen" label appears on the screen at application startup.

Note Get familiar with instructions on how to create an empty application at https://developer.tizen.org/development/getting-started/native-application/creating-your-first-tizen-application.

2 Start the Maps Service

To start the Maps Service:

  1. Include the Maps Service API header file in your application:

    #include <maps_service.h>
    Note This inclusion allows you to use all native Maps Service API functions and features. For more details, see https://developer.tizen.org/development/api-references/, and go to 2.4 API References -> Native Application -> Mobile Native -> Native API Reference -> Location -> Maps Service.
  2. Add a Maps Service handle to the appdata_s structure:
    typedef struct 
    appdata 
    {
       Evas_Object *win;
       Evas_Object *conform;
       Evas_Object *label;
       maps_service_h maps; // Maps Service handle
    } appdata_s;
  3. Create the Maps Service instance in the app_create() function:
    static bool
    app_create(void *data)
    {
       appdata_s *ad = data;
       create_base_gui(ad);
    
       // Specify the maps provider name
       if (maps_service_create("HERE", &ad->maps) != MAPS_ERROR_NONE)
          return false;
    
       // Set the security key issued by the maps provider
       maps_service_set_provider_key(ad->maps, "your-security-key");
    
       return true;
    }
  4. When no longer needed, destroy the Maps Service instance in the app_terminate() function:
    static void
    app_terminate(void *data)
    {
       // Release all resources
       appdata_s *ad = data;
       maps_service_destroy(ad->maps);
    }

3 Run a Reverse Geocode Request

To run a reverse geocode request:

  1. Add the reverse geocode request into the app_create() function:

    // Use the Reverse Geocode API
    int request_id = 0;
    maps_service_reverse_geocode(ad->maps, 55.7601365, 37.6164599, NULL, reverse_geocode_cb, ad, &request_id);
  2. Implement the reverse qeocode callback:
    static void
    reverse_geocode_cb(maps_error_e result, int request_id, int index, int total,
    		   maps_address_h address, void* user_data)
    {
       char *city = NULL;
       char *street = NULL;
       char *building_number = NULL;
    
       maps_address_get_city(address, &city);
       maps_address_get_street(address, &street);
       maps_address_get_building_number(address, &building_number);
    
       char reverse_geocode[0x80] = {0};
       snprintf(reverse_geocode, 0x80, "Reverse Geocode is: %s, %s, %s", building_number, street, city);
    
       appdata_s *ad = user_data;
       elm_object_text_set(ad->label, reverse_geocode);
    
       // Release the results
       free(city);
       free(street);
       free(building_number);
       maps_address_destroy(address);
    }
  3. Run the application.

    At first, the familiar "Hello Tizen" line appears. A moment later, however, it changes to "Reverse Geocode is: 6, ulitsa Bol'shaya Dmitrovka, Moscow”.
    This indicates the reverse geocode of the geographical coordinates (55.7601365, 37.6164599).

Reference

https://developer.tizen.org/development/tutorials/native-application/location/maps-service#geocode

List
SDK Version Since: 
2.4.0