Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: content/public/common/geoposition.cc

Issue 454253002: Location chooser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing meacer@ comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« content/public/common/geoposition.h ('K') | « content/public/common/geoposition.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/common/geoposition.cc
diff --git a/content/public/common/geoposition.cc b/content/public/common/geoposition.cc
index 3a0f1f08b1847e4e6b616a38b7e7813bc99f4446..39174222202029b5a312519d5cad8b2437574414 100644
--- a/content/public/common/geoposition.cc
+++ b/content/public/common/geoposition.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "content/public/common/geoposition.h"
+#include <math.h>
namespace {
// Sentinel values to mark invalid data. (WebKit carries companion is_valid
@@ -36,4 +37,29 @@ bool Geoposition::Validate() const {
!timestamp.is_null();
}
+// The calculations in this function are experimental and not fully accurate.
+/* static */
+Geoposition Geoposition::ApplyPrecision(const Geoposition& position,
+ const int precision) {
+ Geoposition newGeoposition = position;
+ switch (precision) {
+ case 1:
+ // City granuality.
+ newGeoposition.latitude = round(newGeoposition.latitude * 10.0) / 10.0;
+ newGeoposition.longitude = round(newGeoposition.longitude * 10.0) / 10.0;
+ break;
+ case 2:
+ // State granuality.
+ newGeoposition.latitude = round(newGeoposition.latitude);
+ newGeoposition.longitude = round(newGeoposition.longitude);
+ break;
+ case 3:
+ // Country granuality.
+ newGeoposition.latitude = round(newGeoposition.latitude / 10.0);
+ newGeoposition.longitude = round(newGeoposition.longitude / 10.0);
+ break;
+ }
+ return newGeoposition;
+}
+
} // namespace content
« content/public/common/geoposition.h ('K') | « content/public/common/geoposition.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698