[go: nahoru, domu]

blob: 8909d4a6fa2dafc118fd8f815efe91831536628b [file] [log] [blame]
alemate@chromium.org9e844cf2014-04-19 02:36:011// 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.
4
satoruxde6a5dc2014-12-12 22:30:375#include "chromeos/geolocation/geoposition.h"
alemate@chromium.org9e844cf2014-04-19 02:36:016
7#include "base/strings/stringprintf.h"
8
9namespace {
10
11// Sentinel values to mark invalid data.
12const double kBadLatitudeLongitude = 200;
13const int kBadAccuracy = -1; // Accuracy must be non-negative.
14
15} // namespace
16
17namespace chromeos {
18
19Geoposition::Geoposition()
20 : latitude(kBadLatitudeLongitude),
21 longitude(kBadLatitudeLongitude),
22 accuracy(kBadAccuracy),
23 error_code(0),
24 status(STATUS_NONE) {
25}
26
27bool Geoposition::Valid() const {
28 return latitude >= -90. && latitude <= 90. && longitude >= -180. &&
29 longitude <= 180. && accuracy >= 0. && !timestamp.is_null() &&
30 status == STATUS_OK;
31}
32
33std::string Geoposition::ToString() const {
34 static const char* const status2string[] = {
35 "NONE",
36 "OK",
37 "SERVER_ERROR",
38 "NETWORK_ERROR",
39 "TIMEOUT"
40 };
41
42 return base::StringPrintf(
43 "latitude=%f, longitude=%f, accuracy=%f, error_code=%u, "
44 "error_message='%s', status=%u (%s)",
45 latitude,
46 longitude,
47 accuracy,
48 error_code,
49 error_message.c_str(),
50 (unsigned)status,
51 (status < arraysize(status2string) ? status2string[status] : "unknown"));
satoruxde6a5dc2014-12-12 22:30:3752}
alemate@chromium.org9e844cf2014-04-19 02:36:0153
54} // namespace chromeos