How to Use Tizen Native Geocode API in 3 Steps

Since Tizen 2.4

What is Geocoding?

Geocoding translates the place address into its geographical coordinates.

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

Tizen Native Geocode API

To start using the Geocode API:

  1. Create an empty Tizen native application.
  2. Start the Maps Service.
  3. Run a 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.

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:
#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.
  1. 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;
  1. 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;
}
  1. 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 Geocode Request

To run a geocode request:

  1. Add the geocode request into the app_create() function:
// Use the Geocode API
int req_id = 0;
maps_service_geocode(ad->maps, "Moscow Bolshoi Theatre", NULL, geocode_cb, ad, &req_id);
  1. Implement the geocode callback:
static bool
geocode_cb(maps_error_e result, int request_id, int index, int total, maps_coordinates_h coordinates, void *user_data)
{
    // Get latitude and longitude of the geocode
    double latitude = .0;
    double longitude = .0;
    maps_coordinates_get_latitude(coordinates, &latitude);
    maps_coordinates_get_longitude(coordinates, &longitude);

    // Output the geocode
    char geocode[64] = {0};
    snprintf(geocode, 64, "Geocode is: (%f, %f)", latitude, longitude);
    appdata_s *ad = user_data;
    elm_object_text_set(ad->label, geocode);

    // Release the coordinates handle
    maps_coordinates_destroy(coordinates);

    // If return true, you receive other geocodes
    // of the address put to the Geocode request
    // In this example, 1 geocode is enough 
    return false;
}
  1. Run the application.

At first,  the familiar "Hello Tizen" line appears. A moment later, however, it changes  to "Geocode is: (55.756970, 37.615020)”.
This indicates the geocode of the Bolshoi Theatre in Moscow.

 

Reference

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

File attachments: 
List
SDK Version Since: 
2.4.0