How to Use the Tizen Native Reverse Geocode API in 3 Steps
PUBLISHED
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.
To start using the Reverse Geocode API:
- Create an empty Tizen native application.
- Start the Maps Service.
- 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”
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
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.
The "Hello Tizen" label appears on the screen at application startup.
2 Start the Maps Service
To start the Maps Service:
- 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. - 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;
- 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; }
- 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:
- 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);
- 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); }
- 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