[geocode-glib] location: Limit Geo URI to 6 decimal points
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geocode-glib] location: Limit Geo URI to 6 decimal points
- Date: Sun, 16 Aug 2015 12:47:49 +0000 (UTC)
commit 5434d78aff76c944ca30b8003364b5369d616112
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Sun Aug 16 14:45:27 2015 +0200
location: Limit Geo URI to 6 decimal points
In order to get prettier Geo URIs we can limit the precision
of the coords to 6 decimal points. The URIs will not look crazy
and we still get 0.1m precision.
geocode-glib/geocode-location.c | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/geocode-glib/geocode-location.c b/geocode-glib/geocode-location.c
index c5bbe98..6f70c58 100644
--- a/geocode-glib/geocode-location.c
+++ b/geocode-glib/geocode-location.c
@@ -816,9 +816,18 @@ geocode_location_get_timestamp (GeocodeLocation *loc)
return loc->priv->timestamp;
}
+static gdouble
+round_coord_n (gdouble coord, guint n)
+{
+ gdouble fac = pow (10, n);
+
+ return round (coord * fac) / fac;
+}
+
static char *
geo_uri_from_location (GeocodeLocation *loc)
{
+ guint precision = 6; /* 0.1 meter precision */
char *uri;
char *coords;
char *params;
@@ -830,8 +839,14 @@ geo_uri_from_location (GeocodeLocation *loc)
g_return_val_if_fail (GEOCODE_IS_LOCATION (loc), NULL);
- g_ascii_dtostr (lat, G_ASCII_DTOSTR_BUF_SIZE, loc->priv->latitude);
- g_ascii_dtostr (lon, G_ASCII_DTOSTR_BUF_SIZE, loc->priv->longitude);
+ g_ascii_formatd (lat,
+ G_ASCII_DTOSTR_BUF_SIZE,
+ "%.6f",
+ round_coord_n (loc->priv->latitude, precision));
+ g_ascii_formatd (lon,
+ G_ASCII_DTOSTR_BUF_SIZE,
+ "%.6f",
+ round_coord_n (loc->priv->longitude, precision));
if (loc->priv->altitude != GEOCODE_LOCATION_ALTITUDE_UNKNOWN) {
g_ascii_dtostr (alt, G_ASCII_DTOSTR_BUF_SIZE,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]