Languages

Menu
Sites
Language
How tizen native app get and parse JSON data from google map api

Hi,

I am new trizen native app developer.I want to get and parse data from google map api (like this url:  maps.googleapis.com/maps/api/place/nearbysearch/xml?types=restaurant&radius=500&location=23.7489959,90.3917064&sensor=true&key=AIzaSyDHR9lSsc7jB8VtYuj6NuaK6QcspfFUnZQ) and want display in list view.

Anyone please help me with sample code.

Responses

8 Replies
Marco Buettner

For native apps you can use json-glib, which is already included in Tizen

https://developer.tizen.org/native-application?redirect=https%3A//developer.tizen.org/dev-guide/2.3.0/org.tizen.native.mobile.apireference/index.html

Jean Yang

you can use the curl lib to get json data from the google map api. search in IDE help as the beginning regarding curl programming. :)

Vikram

code snippets:

#include <curl/curl.h>


static char error_buffer[CURL_ERROR_SIZE];
static CURL *conn = NULL;


bool webapi_init(char *url, char *buffer, curl_write_callback writer)
{
    CURLcode code;

	curl_global_init(CURL_GLOBAL_ALL);

    conn = curl_easy_init();
    if (conn == NULL)
    {
        dlog_print(DLOG_INFO, LOG_TAG, "Failed to create CURL connection\n");
        exit(EXIT_FAILURE);
    }

    code = curl_easy_setopt(conn, CURLOPT_ERRORBUFFER, error_buffer);
    if (code != CURLE_OK)
    {
    	dlog_print(DLOG_INFO, LOG_TAG, "Failed to set error buffer [%d]\n", code);
        return false;
    }

    code = curl_easy_setopt(conn, CURLOPT_URL, url);
    if (code != CURLE_OK)
    {
    	dlog_print(DLOG_INFO, LOG_TAG, "Failed to set URL [%s]\n", error_buffer);
        return false;
    }

    code = curl_easy_setopt(conn, CURLOPT_FOLLOWLOCATION, 1L);
    if (code != CURLE_OK)
    {
    	dlog_print(DLOG_INFO, LOG_TAG, "Failed to set redirect option [%s]\n", error_buffer);

        return false;
    }

    code = curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writer);
    if (code != CURLE_OK)
    {
    	dlog_print(DLOG_INFO, LOG_TAG, "Failed to set writer [%s]\n", error_buffer);

        return false;
    }

    code = curl_easy_setopt(conn, CURLOPT_WRITEDATA, buffer);
    if (code != CURLE_OK)
    {
    	dlog_print(DLOG_INFO, LOG_TAG, "Failed to set write data [%s]\n", error_buffer);
        return false;
    }
    //curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, FALSE);
    //curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, FALSE);

    return true;
}


int webapi_getresponse()
{
	CURLcode code;
	// Retrieve content for the URL
    code = curl_easy_perform(conn);
    return code;
}


void webapi_destroy()
{
	/* cleanup curl stuff */
    curl_easy_cleanup(conn);
	/* we're done with libcurl, so clean it up */
    curl_global_cleanup();
}

Call the api to get a http resource,

    webapi_init(url, (void *)&buffer, WriteMemoryCallback);
    int r = webapi_getresponse();
    webapi_destroy();

John Ixion

https://developer.tizen.org/documentation/articles/native-application-dev-tip-tutorial-json-parser

Alex Dem

Hi,
Maybe this tutorial with example could be useful:
https://developer.tizen.org/documentation/articles/native-application-dev-tip-tutorial-json-parser
Alexey.

A.T.M. Alaul Haque

thanks for response...

I fetched http data from URL using CURL and get in into array...but my objective display data in list view any one please help me with example...

 

static size_t function_pt(char *buf, size_t size, size_t nmemb, void *stream){
    dlog_print(DLOG_ERROR, "USR_TAG", "function_pt Called %d", size * nmemb);

    if (buf == NULL)
        dlog_print(DLOG_ERROR, "USR_TAG", "buf is NULL");
    else {
        for (unsigned int c = 0; c < size * nmemb; c++) {
            respdata.push_back(buf[c]);
            dlog_print(DLOG_ERROR, "USR_TAG", "Curl returned data = %s", respdata.c_str());
            parseArray_clicked_cb(&buf);
        }
    }
    return size * nmemb;
}

to list view....

Vikram

you can get sample code from the "UI Controls" sample project in IDE. its main ui is a list view, please check the source code in main.c 

colin Rao

first, create a list,

Evas_Object *list;

/* List */
list = elm_list_add(parent);
elm_list_mode_set(list, ELM_LIST_COMPRESS);

then,

foreach you list and call,

elm_list_item_append();

to append your list item data to the list widget.