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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/public/common/geoposition.h" 5 #include "content/public/common/geoposition.h"
6 #include <math.h>
6 7
7 namespace { 8 namespace {
8 // Sentinel values to mark invalid data. (WebKit carries companion is_valid 9 // Sentinel values to mark invalid data. (WebKit carries companion is_valid
9 // bools for this purpose; we may eventually follow that approach, but 10 // bools for this purpose; we may eventually follow that approach, but
10 // sentinels worked OK in the Gears code this is based on.) 11 // sentinels worked OK in the Gears code this is based on.)
11 const double kBadLatitudeLongitude = 200; 12 const double kBadLatitudeLongitude = 200;
12 // Lowest point on land is at approximately -400 meters. 13 // Lowest point on land is at approximately -400 meters.
13 const int kBadAltitude = -10000; 14 const int kBadAltitude = -10000;
14 const int kBadAccuracy = -1; // Accuracy must be non-negative. 15 const int kBadAccuracy = -1; // Accuracy must be non-negative.
15 const int kBadHeading = -1; // Heading must be non-negative. 16 const int kBadHeading = -1; // Heading must be non-negative.
(...skipping 13 matching lines...) Expand all
29 error_code(ERROR_CODE_NONE) { 30 error_code(ERROR_CODE_NONE) {
30 } 31 }
31 32
32 bool Geoposition::Validate() const { 33 bool Geoposition::Validate() const {
33 return latitude >= -90. && latitude <= 90. && 34 return latitude >= -90. && latitude <= 90. &&
34 longitude >= -180. && longitude <= 180. && 35 longitude >= -180. && longitude <= 180. &&
35 accuracy >= 0. && 36 accuracy >= 0. &&
36 !timestamp.is_null(); 37 !timestamp.is_null();
37 } 38 }
38 39
40 // The calculations in this function are experimental and not fully accurate.
41 /* static */
42 Geoposition Geoposition::ApplyPrecision(const Geoposition& position,
43 const int precision) {
44 Geoposition newGeoposition = position;
45 switch (precision) {
46 case 1:
47 // City granuality.
48 newGeoposition.latitude = round(newGeoposition.latitude * 10.0) / 10.0;
49 newGeoposition.longitude = round(newGeoposition.longitude * 10.0) / 10.0;
50 break;
51 case 2:
52 // State granuality.
53 newGeoposition.latitude = round(newGeoposition.latitude);
54 newGeoposition.longitude = round(newGeoposition.longitude);
55 break;
56 case 3:
57 // Country granuality.
58 newGeoposition.latitude = round(newGeoposition.latitude / 10.0);
59 newGeoposition.longitude = round(newGeoposition.longitude / 10.0);
60 break;
61 }
62 return newGeoposition;
63 }
64
39 } // namespace content 65 } // namespace content
OLDNEW
« 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