geoposition.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.
  4. #include "ash/components/geolocation/geoposition.h"
  5. #include "base/strings/stringprintf.h"
  6. namespace {
  7. // Sentinel values to mark invalid data.
  8. const double kBadLatitudeLongitude = 200;
  9. const int kBadAccuracy = -1; // Accuracy must be non-negative.
  10. } // namespace
  11. namespace ash {
  12. Geoposition::Geoposition()
  13. : latitude(kBadLatitudeLongitude),
  14. longitude(kBadLatitudeLongitude),
  15. accuracy(kBadAccuracy),
  16. error_code(0),
  17. status(STATUS_NONE) {
  18. }
  19. bool Geoposition::Valid() const {
  20. return latitude >= -90. && latitude <= 90. && longitude >= -180. &&
  21. longitude <= 180. && accuracy >= 0. && !timestamp.is_null() &&
  22. status == STATUS_OK;
  23. }
  24. std::string Geoposition::ToString() const {
  25. static const char* const status2string[] = {
  26. "NONE",
  27. "OK",
  28. "SERVER_ERROR",
  29. "NETWORK_ERROR",
  30. "TIMEOUT"
  31. };
  32. return base::StringPrintf(
  33. "latitude=%f, longitude=%f, accuracy=%f, error_code=%u, "
  34. "error_message='%s', status=%u (%s)",
  35. latitude, longitude, accuracy, error_code, error_message.c_str(),
  36. (unsigned)status,
  37. (status < std::size(status2string) ? status2string[status] : "unknown"));
  38. }
  39. } // namespace ash