forked from organicmaps/organicmaps
Added helper functions to coordinates formatting
This commit is contained in:
parent
a0168ec38c
commit
520ac0224a
3 changed files with 28 additions and 2 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "../platform/settings.hpp"
|
||||
|
||||
#include "../indexer/mercator.hpp"
|
||||
|
||||
#include "../base/string_utils.hpp"
|
||||
#include "../base/math.hpp"
|
||||
|
||||
|
@ -106,4 +108,20 @@ string FormatLatLonAsDMS(double lat, double lon, int dac)
|
|||
FormatLatLonAsDMSImpl(lon, 'E', 'W', dac));
|
||||
}
|
||||
|
||||
string FormatMercatorAsDMS(m2::PointD const & mercator, int dac)
|
||||
{
|
||||
return FormatLatLonAsDMS(MercatorBounds::YToLat(mercator.y), MercatorBounds::XToLon(mercator.x), dac);
|
||||
}
|
||||
|
||||
// @TODO take into account decimal points or commas as separators in different locales
|
||||
string FormatLatLon(double lat, double lon, int dac)
|
||||
{
|
||||
return strings::to_string_dac(lat, dac) + ", " + strings::to_string_dac(lon, dac);
|
||||
}
|
||||
|
||||
string FormatMercator(m2::PointD const & mercator, int dac)
|
||||
{
|
||||
return FormatLatLon(MercatorBounds::YToLat(mercator.y), MercatorBounds::XToLon(mercator.x), dac);
|
||||
}
|
||||
|
||||
} // namespace MeasurementUtils
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../geometry/point2d.hpp"
|
||||
|
||||
#include "../std/string.hpp"
|
||||
|
||||
namespace MeasurementUtils
|
||||
|
@ -22,6 +24,10 @@ bool FormatDistance(double m, string & res);
|
|||
|
||||
/// @param[in] dac Digits after comma in seconds.
|
||||
/// Use dac == 3 for our common conversions.
|
||||
string FormatLatLonAsDMS(double lat, double lon, int dac = 0);
|
||||
string FormatLatLonAsDMS(double lat, double lon, int dac = 3);
|
||||
string FormatMercatorAsDMS(m2::PointD const & mercator, int dac = 3);
|
||||
/// Simple decimal degrees formating
|
||||
string FormatLatLon(double lat, double lon, int dac = 6);
|
||||
string FormatMercator(m2::PointD const & mercator, int dac = 6);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#include "ftypes_matcher.hpp"
|
||||
#include "geometry_utils.hpp"
|
||||
|
||||
#include "../map/measurement_utils.hpp"
|
||||
|
||||
#include "../storage/country_info.hpp"
|
||||
|
||||
#include "../indexer/classificator.hpp"
|
||||
|
@ -166,7 +168,7 @@ PreResult2::PreResult2(FeatureType const & f, PreResult1 const * p,
|
|||
}
|
||||
|
||||
PreResult2::PreResult2(m2::RectD const & viewport, m2::PointD const & pos, double lat, double lon)
|
||||
: m_str("(" + strings::to_string_dac(lat, 5) + ", " + strings::to_string_dac(lon, 5) + ")"),
|
||||
: m_str("(" + MeasurementUtils::FormatLatLon(lat, lon) + ")"),
|
||||
m_resultType(RESULT_LATLON),
|
||||
m_rank(255),
|
||||
m_geomType(feature::GEOM_UNDEFINED)
|
||||
|
|
Loading…
Add table
Reference in a new issue