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 5 #include "chrome/browser/chromeos/geolocation/geoposition.h" 6 7 #include "base/strings/stringprintf.h" 8 9 namespace { 10 11 // Sentinel values to mark invalid data. 12 const double kBadLatitudeLongitude = 200; 13 const int kBadAccuracy = -1; // Accuracy must be non-negative. 14 15 } // namespace 16 17 namespace chromeos { 18 19 Geoposition::Geoposition() 20 : latitude(kBadLatitudeLongitude), 21 longitude(kBadLatitudeLongitude), 22 accuracy(kBadAccuracy), 23 error_code(0), 24 status(STATUS_NONE) { 25 } 26 27 bool 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 33 std::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")); 52 }; 53 54 } // namespace chromeos 55