
/* gcc -o geocode-test `pkg-config --cflags --libs geocode-glib-1.0` geocode-test.c */

#include <stdio.h>
#include <geocode-glib/geocode-glib.h>

static void
resolve_ready (GeocodeReverse *rev,
               GAsyncResult   *res,
               GMainLoop      *loop)
{
	GError *error = NULL;
	GeocodePlace *place;

	place = geocode_reverse_resolve_finish (rev, res, &error);
	if (!place) {
		g_warning ("Failed at reverse geocoding: %s", error->message);
		g_error_free (error);
	} else {
		GeocodeLocation *loc;

		loc = geocode_place_get_location (place);
		g_print ("\t%s @ %lf, %lf\n",
		         geocode_location_get_description (loc),
		         geocode_location_get_latitude (loc),
		         geocode_location_get_longitude (loc));
		g_object_unref (place);
	}

	g_main_loop_quit (loop);
}

int main (int argc, char **argv)
{
	GeocodeLocation *loc;
	GeocodeReverse *rev;
	GMainLoop *loop;

	loop = g_main_loop_new (NULL, FALSE);

	loc = geocode_location_new (51.2370361, -0.5894834, GEOCODE_LOCATION_ACCURACY_UNKNOWN);
	rev = geocode_reverse_new_for_location (loc);
	g_object_unref (loc);

	geocode_reverse_resolve_async (rev, NULL, (GAsyncReadyCallback) resolve_ready, loop);
	g_object_unref (rev);

	g_main_loop_run (loop);
	g_main_loop_unref (loop);

	return 0;
}
