1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/geolocation/geoposition.h"
7 #include "base/strings/stringprintf.h"
11 // Sentinel values to mark invalid data.
12 const double kBadLatitudeLongitude
= 200;
13 const int kBadAccuracy
= -1; // Accuracy must be non-negative.
19 Geoposition::Geoposition()
20 : latitude(kBadLatitudeLongitude
),
21 longitude(kBadLatitudeLongitude
),
22 accuracy(kBadAccuracy
),
27 bool Geoposition::Valid() const {
28 return latitude
>= -90. && latitude
<= 90. && longitude
>= -180. &&
29 longitude
<= 180. && accuracy
>= 0. && !timestamp
.is_null() &&
33 std::string
Geoposition::ToString() const {
34 static const char* const status2string
[] = {
42 return base::StringPrintf(
43 "latitude=%f, longitude=%f, accuracy=%f, error_code=%u, "
44 "error_message='%s', status=%u (%s)",
49 error_message
.c_str(),
51 (status
< arraysize(status2string
) ? status2string
[status
] : "unknown"));
54 } // namespace chromeos