/** * geoclue_poi_address_to_position_async: * @poi: A #GeocluePoi object * @details: A #GHashTable with address data * @callback: A #GeoclueAddressCallback function that should be called when return values are available * @userdata: pointer for user specified data * * Function returns (essentially) immediately and calls @callback when the poid * position data is available or when D-Bus timeouts. * * see <ulink url="geoclue-types.html">geoclue-types.h</ulink> for the * hashtable keys usable in @details. * */ void geoclue_poi_search_by_position_async (GeocluePoi *poi, const char *keyword, const char *lang, const char *country_code, int limit, double left, double top, double right, double bottom, GeocluePoiCallback callback, gpointer userdata) { GeoclueProvider *provider = GEOCLUE_PROVIDER (poi); GeocluePoiAsyncData *data; data = g_new (GeocluePoiAsyncData, 1); data->poi = poi; data->callback = G_CALLBACK (callback); data->userdata = userdata; org_freedesktop_Geoclue_Poi_search_by_position_async (provider->proxy, keyword, lang, country_code, limit, left, top, right, bottom, (org_freedesktop_Geoclue_Poi_search_by_position_reply)_geoclue_poi_callback, data); }
int location_geoclue_start(location_geoclue_state_t *state) { if (state->provider && state->provider_path) { state->position = geoclue_position_new(state->provider, state->provider_path); } else { GError *error = NULL; GeoclueMaster *master = geoclue_master_get_default(); GeoclueMasterClient *client = geoclue_master_create_client(master, NULL, &error); g_object_unref(master); if (client == NULL) { g_printerr(_("Unable to obtain master client: %s\n"), error->message); g_error_free(error); return -1; } if (!geoclue_master_client_set_requirements(client, GEOCLUE_ACCURACY_LEVEL_REGION, 0, FALSE, GEOCLUE_RESOURCE_NETWORK, &error)) { g_printerr(_("Can't set requirements for master: %s\n"), error->message); g_error_free(error); g_object_unref(client); return -1; } state->position = geoclue_master_client_create_position(client, NULL); g_object_unref(client); } gchar *name = NULL; if (geoclue_provider_get_provider_info(GEOCLUE_PROVIDER(state->position), &name, NULL, NULL)) { fprintf(stdout, _("Started Geoclue provider `%s'.\n"), name); g_free(name); } else { fputs(_("Could not find a usable Geoclue provider.\n"), stderr); fputs(_("Try setting name and path to specify which to use.\n"), stderr); return -1; } return 0; }
/** * geoclue_position_get_position_async: * @position: A #GeocluePosition object * @callback: A #GeocluePositionCallback function that should be called when return values are available * @userdata: pointer for user specified data * * Function returns (essentially) immediately and calls @callback when current position * is available or when D-Bus timeouts. */ void geoclue_position_get_position_async (GeocluePosition *position, GeocluePositionCallback callback, gpointer userdata) { GeoclueProvider *provider = GEOCLUE_PROVIDER (position); GeocluePositionAsyncData *data; data = g_new (GeocluePositionAsyncData, 1); data->position = position; data->callback = G_CALLBACK (callback); data->userdata = userdata; org_freedesktop_Geoclue_Position_get_position_async (provider->proxy, (org_freedesktop_Geoclue_Position_get_position_reply)get_position_async_callback, data); }
/** * geoclue_position_get_position: * @position: A #GeocluePosition object * @timestamp: Pointer to returned time of position measurement (Unix timestamp) or %NULL * @latitude: Pointer to returned latitude in degrees or %NULL * @longitude: Pointer to returned longitude in degrees or %NULL * @altitude: Pointer to returned altitude in meters or %NULL * @accuracy: Pointer to returned #GeoclueAccuracy or %NULL * @error: Pointer to returned #Gerror or %NULL * * Obtains the current position. @timestamp will contain the time of * the actual position measurement. @accuracy is a rough estimate of the * accuracy of the current position. * * If the caller is not interested in some values, the pointers can be * left %NULL. * * Return value: A #GeocluePositionFields bitfield representing the * validity of the position values. */ GeocluePositionFields geoclue_position_get_position (GeocluePosition *position, int *timestamp, double *latitude, double *longitude, double *altitude, GeoclueAccuracy **accuracy, GError **error) { GeoclueProvider *provider = GEOCLUE_PROVIDER (position); double la, lo, al; int ts, fields; GeoclueAccuracy *acc; if (!org_freedesktop_Geoclue_Position_get_position (provider->proxy, &fields, &ts, &la, &lo, &al, &acc, error)) { return GEOCLUE_POSITION_FIELDS_NONE; } if (timestamp != NULL) { *timestamp = ts; } if (latitude != NULL && (fields & GEOCLUE_POSITION_FIELDS_LATITUDE)) { *latitude = la; } if (longitude != NULL && (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)) { *longitude = lo; } if (altitude != NULL && (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE)) { *altitude = al; } if (accuracy != NULL) { *accuracy = acc; } return fields; }
/** * geoclue_geocode_freeform_address_to_position_async: * @geocode: A #Geocluegeocode object * @address: freeform address * @callback: A #GeoclueAddressCallback function that should be called when return values are available * @userdata: pointer for user specified data * * Function returns (essentially) immediately and calls @callback when the geocoded * position data is available or when D-Bus timeouts. */ void geoclue_geocode_freeform_address_to_position_async (GeoclueGeocode *geocode, const char *address, GeoclueGeocodeCallback callback, gpointer userdata) { GeoclueProvider *provider = GEOCLUE_PROVIDER (geocode); GeoclueGeocodeAsyncData *data; data = g_new (GeoclueGeocodeAsyncData, 1); data->geocode = geocode; data->callback = G_CALLBACK (callback); data->userdata = userdata; org_freedesktop_Geoclue_Geocode_freeform_address_to_position_async (provider->proxy, address, (org_freedesktop_Geoclue_Geocode_address_to_position_reply)address_to_position_callback, data); }
/** * geoclue_geocode_freeform_address_to_position: * @geocode: A #GeoclueGeocode object * @address: freeform address * @latitude: Pointer to returned latitude in degrees or %NULL * @longitude: Pointer to returned longitude in degrees or %NULL * @altitude: Pointer to returned altitude in meters or %NULL * @accuracy: Pointer to returned #GeoclueAccuracy or %NULL * @error: Pointer to returned #Gerror or %NULL * * Geocodes given address to coordinates (@latitude, @longitude, @altitude). * @accuracy is a rough estimate of the accuracy of the returned position. * * If the caller is not interested in some values, the pointers can be * left %NULL. * * Return value: A #GeocluePositionFields bitfield representing the * validity of the returned coordinates. */ GeocluePositionFields geoclue_geocode_freeform_address_to_position (GeoclueGeocode *geocode, const char *address, double *latitude, double *longitude, double *altitude, GeoclueAccuracy **accuracy, GError **error) { GeoclueProvider *provider = GEOCLUE_PROVIDER (geocode); int fields; double la, lo, al; GeoclueAccuracy *acc; if (!org_freedesktop_Geoclue_Geocode_freeform_address_to_position (provider->proxy, address, &fields, &la, &lo, &al, &acc, error)) { return GEOCLUE_POSITION_FIELDS_NONE; } if (latitude != NULL && (fields & GEOCLUE_POSITION_FIELDS_LATITUDE)) { *latitude = la; } if (longitude != NULL && (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)) { *longitude = lo; } if (altitude != NULL && (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE)) { *altitude = al; } if (accuracy != NULL) { *accuracy = acc; } return fields; }
/** * geoclue_poi_address_to_position: * @poi: A #GeocluePoi object * @details: Hashtable with address data * @latitude: Pointer to returned latitude in degrees or %NULL * @longitude: Pointer to returned longitude in degrees or %NULL * @altitude: Pointer to returned altitude in meters or %NULL * @accuracy: Pointer to returned #GeoclueAccuracy or %NULL * @error: Pointer to returned #Gerror or %NULL * * Pois given address to coordinates (@latitude, @longitude, @altitude). * see <ulink url="geoclue-types.html">geoclue-types.h</ulink> for the * hashtable keys usable in @details. @accuracy is a rough estimate of * the accuracy of the returned position. * * If the caller is not interested in some values, the pointers can be * left %NULL. * * Return value: A #GeocluePositionFields bitfield representing the * validity of the returned coordinates. */ gboolean geoclue_poi_search_by_position (GeocluePoi *poi, const char *keyword, const char *lang, const char *country_code, int limit, double left, double top, double right, double bottom, int *count, GPtrArray **landmark, GError **error) { GeoclueProvider *provider = GEOCLUE_PROVIDER (poi); if (!org_freedesktop_Geoclue_Poi_search_by_position (provider->proxy, keyword, lang, country_code, limit, left, top, right, bottom, count, landmark, error)){ return FALSE; } return TRUE; }
static GObject * constructor (GType type, guint n_props, GObjectConstructParam *props) { GObject *object; GeoclueProvider *provider; object = G_OBJECT_CLASS (geoclue_position_parent_class)->constructor (type, n_props, props); provider = GEOCLUE_PROVIDER (object); dbus_g_proxy_add_signal (provider->proxy, "PositionChanged", G_TYPE_INT, G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE, GEOCLUE_ACCURACY_TYPE, G_TYPE_INVALID); dbus_g_proxy_connect_signal (provider->proxy, "PositionChanged", G_CALLBACK (position_changed), object, NULL); return object; }
int main (int argc, char** argv) { gchar *service, *path; GeocluePosition *pos = NULL; GeocluePositionFields fields; int timestamp; double lat, lon; GeoclueAccuracy *accuracy = NULL; GMainLoop *mainloop; GError *error = NULL; g_type_init(); if (argc < 2 || argc % 2 != 0) { g_printerr ("Usage:\n position-example <provider_name> [option value]\n"); return 1; } g_print ("Using provider '%s'\n", argv[1]); service = g_strdup_printf ("org.freedesktop.Geoclue.Providers.%s", argv[1]); path = g_strdup_printf ("/org/freedesktop/Geoclue/Providers/%s", argv[1]); mainloop = g_main_loop_new (NULL, FALSE); /* Create new GeocluePosition */ pos = geoclue_position_new (service, path); if (pos == NULL) { g_printerr ("Error while creating GeocluePosition object.\n"); return 1; } g_free (service); g_free (path); if (argc > 2) { GHashTable *options; options = parse_options (argc, argv); if (!geoclue_provider_set_options (GEOCLUE_PROVIDER (pos), options, &error)) { g_printerr ("Error setting options: %s\n", error->message); g_error_free (error); error = NULL; } g_hash_table_destroy (options); } /* Query current position. We're not interested in altitude this time, so leave it NULL. Same can be done with all other arguments that aren't interesting to the client */ fields = geoclue_position_get_position (pos, ×tamp, &lat, &lon, NULL, &accuracy, &error); if (error) { g_printerr ("Error getting position: %s\n", error->message); g_error_free (error); g_object_unref (pos); return 1; } /* Print out coordinates if they are valid */ if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE && fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) { GeoclueAccuracyLevel level; double horiz_acc; geoclue_accuracy_get_details (accuracy, &level, &horiz_acc, NULL); g_print ("Current position:\n"); g_print ("\t%f, %f\n", lat, lon); g_print ("\tAccuracy level %d (%.0f meters)\n", level, horiz_acc); } else { g_print ("Latitude and longitude not available.\n"); } geoclue_accuracy_free (accuracy); g_signal_connect (G_OBJECT (pos), "position-changed", G_CALLBACK (position_changed_cb), NULL); g_main_loop_run (mainloop); return 0; }