Пример #1
0
static void
position_callback (GeocluePosition      *pos,
		   GeocluePositionFields fields,
		   int                   timestamp,
		   double                latitude,
		   double                longitude,
		   double                altitude,
		   GeoclueAccuracy      *accuracy,
		   GError               *error,
		   gpointer              userdata)
{
	if (error) {
		g_printerr ("Error getting initial position: %s\n", error->message);
		g_error_free (error);
	} else {
		if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE &&
		    fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) {
			GeoclueAccuracyLevel level;
			
			geoclue_accuracy_get_details (accuracy, &level, NULL, NULL);
			g_print ("Initial position (accuracy %d):\n", level);
			g_print ("\t%f, %f\n", latitude, longitude);
		} else {
			g_print ("Initial position not available.\n");
		}
	}
}
Пример #2
0
static void
position_changed_cb (GeocluePosition      *position,
		     GeocluePositionFields fields,
		     int                   timestamp,
		     double                latitude,
		     double                longitude,
		     double                altitude,
		     GeoclueAccuracy      *accuracy,
		     gpointer              userdata)
{
	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", latitude, longitude);
		g_print ("\tAccuracy level %d (%.0f meters)\n", level, horiz_acc);
		
	} else {
		g_print ("Latitude and longitude not available.\n");
	}
}
/**
 * geoclue_accuracy_copy:
 * @accuracy: A #GeoclueAccuracy
 *
 * Creates a copy of @accuracy.
 *
 * Return value: A newly allocated #GeoclueAccuracy
 */
GeoclueAccuracy *
geoclue_accuracy_copy (GeoclueAccuracy *accuracy)
{
	GeoclueAccuracyLevel level;
	double hor, ver;

	geoclue_accuracy_get_details (accuracy, &level, &hor, &ver);
	return geoclue_accuracy_new (level, hor, ver);
}
/**
 * geoclue_accuracy_comapre:
 * @accuracy1: First GeoclueAccuracy
 * @accuracy1: Second GeoclueAccuracy
 *
 * Compares two accuracies.
 *
 * Return value: 0 if accuracies are same, negative value if accuracy1 is more accurate than accuracy2, or positive value if accuracy1 is less accurate than accuracy2
 */
int
geoclue_accuracy_compare (GeoclueAccuracy *accuracy1, GeoclueAccuracy *accuracy2)
{
	GeoclueAccuracyLevel level1, level2;
	double hor1, hor2;

	geoclue_accuracy_get_details (accuracy1, &level1, &hor1, NULL);
	geoclue_accuracy_get_details (accuracy2, &level2, &hor2, NULL);

	if (level1 == GEOCLUE_ACCURACY_LEVEL_DETAILED &&
	    level2 == GEOCLUE_ACCURACY_LEVEL_DETAILED) {
		if (hor1 > hor2) {
			return 1;
		} else if (hor1 < hor2) {
			return -1;
		}
		return 0;
	}
	return level1 -level2;

}
void GeolocationServiceGtk::position_changed(GeocluePosition*, GeocluePositionFields fields, int timestamp, double latitude, double longitude, double altitude, GeoclueAccuracy* accuracy, GeolocationServiceGtk* that)
{
    if (!(fields & GEOCLUE_POSITION_FIELDS_LATITUDE && fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)) {
        that->setError(PositionError::POSITION_UNAVAILABLE, "Position could not be determined.");
        return;
    }

    that->m_timestamp = timestamp;
    that->m_latitude = latitude;
    that->m_longitude = longitude;
    that->m_altitude = altitude;

    GeoclueAccuracyLevel level;
    geoclue_accuracy_get_details(accuracy, &level, &that->m_accuracy, &that->m_altitudeAccuracy);
    that->updatePosition();
}
Пример #6
0
void GeolocationClient::positionChanged(GeocluePosition*, GeocluePositionFields fields, int timestamp, double latitude, double longitude, double altitude, GeoclueAccuracy* accuracy)
{
    if (!(fields & GEOCLUE_POSITION_FIELDS_LATITUDE && fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)) {
        errorOccured(_("Position could not be determined."));
        return;
    }

    m_timestamp = timestamp;
    m_latitude = latitude;
    m_longitude = longitude;
    m_altitude = altitude;

    geoclue_accuracy_get_details(accuracy, 0, &m_accuracy, &m_altitudeAccuracy);

    updatePosition();
}
static void
accuracy_changed (GypsyAccuracy      *accuracy,
		  GypsyAccuracyFields fields,
		  double              pdop,
		  double              hdop,
		  double              vdop,
		  GeoclueGypsy       *gypsy)
{
	gboolean changed = FALSE;
	GeoclueAccuracyLevel level;
	double horiz, vert;

	geoclue_accuracy_get_details (gypsy->accuracy, &level, &horiz, &vert);
	if (fields & (GYPSY_ACCURACY_FIELDS_HORIZONTAL |
		      GYPSY_ACCURACY_FIELDS_VERTICAL)){
		if (level != GEOCLUE_ACCURACY_LEVEL_DETAILED ||
		    horiz != hdop || vert != vdop) {
			changed = TRUE;
		}

		geoclue_accuracy_set_details (gypsy->accuracy,
					      GEOCLUE_ACCURACY_LEVEL_DETAILED,
					      hdop, vdop);
	} else {

		if (level != GEOCLUE_ACCURACY_LEVEL_NONE ||
		    horiz != 0.0 || vert != 0.0) {
			changed = TRUE;
		}

		geoclue_accuracy_set_details (gypsy->accuracy,
					      GEOCLUE_ACCURACY_LEVEL_NONE,
					      0.0, 0.0);
	}

	if (changed) {
		GeocluePositionFields fields;

		fields = gypsy_position_to_geoclue (gypsy->position_fields);
		gc_iface_position_emit_position_changed
			(GC_IFACE_POSITION (gypsy), fields,
			 gypsy->timestamp, gypsy->latitude, gypsy->longitude,
			 gypsy->altitude, gypsy->accuracy);
	}
}
Пример #8
0
static void
position_changed_cb (GeocluePosition      *position,
		     GeocluePositionFields fields,
		     int                   timestamp,
		     double                latitude,
		     double                longitude,
		     double                altitude,
		     GeoclueAccuracy      *accuracy,
		     gpointer              userdata)
{
	if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE &&
	    fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) {
		GeoclueAccuracyLevel level;
		
		geoclue_accuracy_get_details (accuracy, &level, NULL, NULL);
		g_print ("got position (accuracy level %d):\n", level);
		g_print ("\t%f, %f\n", latitude, longitude);
		
	} else {
		g_print ("position emitted, but latitude and longitude are not valid.\n");
	}
}
Пример #9
0
static gboolean
set_zoom_for_accuracy (EmerillonWindow *self,
                       GeoclueAccuracy *accuracy)
{
  GeoclueAccuracyLevel accuracy_level;
  gint zoom_level;

  geoclue_accuracy_get_details (accuracy, &accuracy_level, NULL, NULL);

  switch (accuracy_level)
    {
      case GEOCLUE_ACCURACY_LEVEL_COUNTRY:
        zoom_level = 4;
        break;
      case GEOCLUE_ACCURACY_LEVEL_REGION:
        zoom_level = 7;
        break;
      case GEOCLUE_ACCURACY_LEVEL_LOCALITY:
        zoom_level = 9;
        break;
      case GEOCLUE_ACCURACY_LEVEL_POSTALCODE:
        zoom_level = 10;
        break;
      case GEOCLUE_ACCURACY_LEVEL_STREET:
        zoom_level = 14;
        break;
      case GEOCLUE_ACCURACY_LEVEL_DETAILED:
        zoom_level = 16;
        break;
      default:
        return FALSE;
    }

  g_object_set (self->priv->view, "zoom-level", zoom_level, NULL);

  return TRUE;
}
static gboolean
get_position (GcIfacePosition       *gc,
	      GeocluePositionFields *fields,
	      int                   *timestamp,
	      double                *latitude,
	      double                *longitude,
	      double                *altitude,
	      GeoclueAccuracy      **accuracy,
	      GError               **error)
{
	GeoclueGypsy *gypsy = GEOCLUE_GYPSY (gc);
	GeoclueAccuracyLevel level;
	double horizontal, vertical;

	*timestamp = gypsy->timestamp;

	*fields = GEOCLUE_POSITION_FIELDS_NONE;
	if (gypsy->position_fields & GYPSY_POSITION_FIELDS_LATITUDE) {
		*fields |= GEOCLUE_POSITION_FIELDS_LATITUDE;
		*latitude = gypsy->latitude;
	}
	if (gypsy->position_fields & GYPSY_POSITION_FIELDS_LONGITUDE) {
		*fields |= GEOCLUE_POSITION_FIELDS_LONGITUDE;
		*longitude = gypsy->longitude;
	}
	if (gypsy->position_fields & GYPSY_POSITION_FIELDS_ALTITUDE) {
		*fields |= GEOCLUE_POSITION_FIELDS_ALTITUDE;
		*altitude = gypsy->altitude;
	}

	geoclue_accuracy_get_details (gypsy->accuracy, &level,
				      &horizontal, &vertical);
	*accuracy = geoclue_accuracy_new (level, horizontal, vertical);

	return TRUE;
}
Пример #11
0
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, &timestamp, 
	                                        &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;
	
}