diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 7824113576..a04b506df6 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -726,9 +726,8 @@ extern "C" { case UserMark::Type::API: { - double lat, lon; - mark->GetLatLon(lat, lon); - CallOnApiPointActivatedListener(obj, CastMark(mark), lat, lon); + ms::LatLon const ll = mark->GetLatLon(); + CallOnApiPointActivatedListener(obj, CastMark(mark), ll.lat, ll.lon); break; } @@ -758,9 +757,8 @@ extern "C" case UserMark::Type::MY_POSITION: { - double lat, lon; - mark->GetLatLon(lat, lon); - CallOnMyPositionActivatedListener(obj, lat, lon); + ms::LatLon const ll = mark->GetLatLon(); + CallOnMyPositionActivatedListener(obj, ll.lat, ll.lon); break; } case UserMark::Type::DEBUG_MARK: diff --git a/geometry/latlon.hpp b/geometry/latlon.hpp index 4ff650d745..dd9b30d834 100644 --- a/geometry/latlon.hpp +++ b/geometry/latlon.hpp @@ -13,6 +13,8 @@ class LatLon public: double lat, lon; + /// Does NOT initialize lat and lon. Allows to use it as a property of an ObjC class. + LatLon() = default; LatLon(double lat, double lon) : lat(lat), lon(lon) {} static LatLon Zero() { return LatLon(0., 0.); } diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.h b/iphone/Maps/Classes/MWMPlacePageEntity.h index a22f27bf0a..4ad68d812e 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.h +++ b/iphone/Maps/Classes/MWMPlacePageEntity.h @@ -45,9 +45,12 @@ typedef NS_ENUM (NSUInteger, MWMPlacePageEntityType) @property (nonatomic) int typeDescriptionValue; @property (nonatomic) BookmarkAndCategory bac; -@property (nonatomic) m2::PointD point; +@property (nonatomic) ms::LatLon ll; @property (weak, nonatomic) MWMPlacePageViewManager * manager; +// Automatically checks if DMS format should be used. +- (NSString *)coordinates; + - (NSArray *)metadataTypes; - (NSArray *)metadataValues; - (void)enableEditing; diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.mm b/iphone/Maps/Classes/MWMPlacePageEntity.mm index fd5bd99ddc..09af76c547 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.mm +++ b/iphone/Maps/Classes/MWMPlacePageEntity.mm @@ -34,9 +34,7 @@ using feature::Metadata; - (void)configureWithUserMark:(UserMark const *)mark { UserMark::Type const type = mark->GetMarkType(); - double x, y; - mark->GetLatLon(x, y); - self.point = m2::PointD(x, y); + self.ll = mark->GetLatLon(); typedef UserMark::Type Type; switch (type) @@ -110,9 +108,7 @@ using feature::Metadata; self.title = L(@"my_position"); self.type = MWMPlacePageEntityTypeMyPosition; [self.metaTypes addObject:kPatternTypesArray.lastObject]; - BOOL const isLatLonAsDMS = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsLatLonAsDMSKey]; - NSString * latLonStr = isLatLonAsDMS ? @(MeasurementUtils::FormatLatLonAsDMS(self.point.x, self.point.y, 2).c_str()): @( MeasurementUtils::FormatLatLon(self.point.x, self.point.y).c_str()); - [self.metaValues addObject:latLonStr]; + [self.metaValues addObject:[self coordinates]]; } - (void)configureForApi:(ApiMarkPoint const *)apiMark @@ -121,10 +117,7 @@ using feature::Metadata; self.title = @(apiMark->GetName().c_str()); self.category = @(GetFramework().GetApiDataHolder().GetAppTitle().c_str()); [self.metaTypes addObject:kPatternTypesArray.lastObject]; - BOOL const isLatLonAsDMS = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsLatLonAsDMSKey]; - NSString * latLonStr = isLatLonAsDMS ? @(MeasurementUtils::FormatLatLonAsDMS(self.point.x, self.point.y, 2).c_str()) : @(MeasurementUtils::FormatLatLon(self.point.x, self.point.y).c_str()); - latLonStr = isLatLonAsDMS ? @(MeasurementUtils::FormatLatLonAsDMS(self.point.x, self.point.y, 2).c_str()) : @(MeasurementUtils::FormatLatLon(self.point.x, self.point.y).c_str()); - [self.metaValues addObject:latLonStr]; + [self.metaValues addObject:[self coordinates]]; } - (void)configureEntityWithMetadata:(Metadata const &)metadata addressInfo:(search::AddressInfo const &)info @@ -221,10 +214,7 @@ using feature::Metadata; } [self.metaTypes addObject:kPatternTypesArray.lastObject]; - BOOL const isLatLonAsDMS = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsLatLonAsDMSKey]; - NSString * latLonStr = isLatLonAsDMS ? @(MeasurementUtils::FormatLatLonAsDMS(self.point.x, self.point.y, 2).c_str()) : @( MeasurementUtils::FormatLatLon(self.point.x, self.point.y).c_str()); - latLonStr = isLatLonAsDMS ? @(MeasurementUtils::FormatLatLonAsDMS(self.point.x, self.point.y, 2).c_str()) : @( MeasurementUtils::FormatLatLon(self.point.x, self.point.y).c_str()); - [self.metaValues addObject:latLonStr]; + [self.metaValues addObject:[self coordinates]]; } - (NSArray *)metadataTypes @@ -279,6 +269,13 @@ using feature::Metadata; } } +- (NSString *)coordinates +{ + BOOL const useDMSFormat = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsLatLonAsDMSKey]; + return @((useDMSFormat ? MeasurementUtils::FormatLatLon(self.ll.lat, self.ll.lon).c_str() + : MeasurementUtils::FormatLatLonAsDMS(self.ll.lat, self.ll.lon, 2).c_str())); +} + #pragma mark - Bookmark editing - (NSString *)bookmarkCategory diff --git a/iphone/Maps/Classes/MWMPlacePageInfoCell.mm b/iphone/Maps/Classes/MWMPlacePageInfoCell.mm index 50619edc54..7899c61705 100644 --- a/iphone/Maps/Classes/MWMPlacePageInfoCell.mm +++ b/iphone/Maps/Classes/MWMPlacePageInfoCell.mm @@ -113,10 +113,11 @@ extern NSString * const kUserDefaultsLatLonAsDMSKey; return; NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; BOOL const showLatLonAsDMS = [defaults boolForKey:kUserDefaultsLatLonAsDMSKey]; - m2::PointD const point = self.currentEntity.point; - [self.textContainer setText:@((showLatLonAsDMS ? MeasurementUtils::FormatLatLon(point.x, point.y).c_str() : MeasurementUtils::FormatLatLonAsDMS(point.x, point.y, 2).c_str()))]; [defaults setBool:!showLatLonAsDMS forKey:kUserDefaultsLatLonAsDMSKey]; [defaults synchronize]; + + // @NOTE: coordinates method depends on kUserDefaultsLatLonAsDMSKey value above. + [self.textContainer setText:[self.currentEntity coordinates]]; } - (void)longTap:(UILongPressGestureRecognizer *)sender diff --git a/iphone/Maps/Classes/MWMPlacePageViewManager.mm b/iphone/Maps/Classes/MWMPlacePageViewManager.mm index 74a3cc678d..77ea499b07 100644 --- a/iphone/Maps/Classes/MWMPlacePageViewManager.mm +++ b/iphone/Maps/Classes/MWMPlacePageViewManager.mm @@ -251,7 +251,7 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"ppShare"]; MWMPlacePageEntity * entity = self.entity; NSString * title = entity.bookmarkTitle ? entity.bookmarkTitle : entity.title; - CLLocationCoordinate2D const coord = CLLocationCoordinate2DMake(entity.point.x, entity.point.y); + CLLocationCoordinate2D const coord = CLLocationCoordinate2DMake(entity.ll.lat, entity.ll.lon); MWMActivityViewController * shareVC = [MWMActivityViewController shareControllerForLocationTitle:title location:coord diff --git a/map/framework.cpp b/map/framework.cpp index 6300fc0632..5a574cf242 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1859,10 +1859,10 @@ UserMark const * Framework::OnTapEventImpl(m2::PointD pxPoint, bool isLong, bool { search::AddressInfo info; info.m_name = m_stringsBundle.GetString("my_position"); - MyPositionMarkPoint * myPostition = UserMarkContainer::UserMarkForMyPostion(); - myPostition->SetInfo(info); + MyPositionMarkPoint * myPosition = UserMarkContainer::UserMarkForMyPostion(); + myPosition->SetInfo(info); - return myPostition; + return myPosition; } df::VisualParams const & vp = df::VisualParams::Instance(); @@ -1957,9 +1957,8 @@ string Framework::GenerateApiBackUrl(ApiMarkPoint const & point) string res = m_ParsedMapApi.GetGlobalBackUrl(); if (!res.empty()) { - double lat, lon; - point.GetLatLon(lat, lon); - res += "pin?ll=" + strings::to_string(lat) + "," + strings::to_string(lon); + ms::LatLon const ll = point.GetLatLon(); + res += "pin?ll=" + strings::to_string(ll.lat) + "," + strings::to_string(ll.lon); if (!point.GetName().empty()) res += "&n=" + UrlEncode(point.GetName()); if (!point.GetID().empty()) diff --git a/map/map_tests/mwm_url_tests.cpp b/map/map_tests/mwm_url_tests.cpp index 08d758aa79..006aa22871 100644 --- a/map/map_tests/mwm_url_tests.cpp +++ b/map/map_tests/mwm_url_tests.cpp @@ -48,9 +48,8 @@ namespace int GetApiVersion() const { return m_api.GetApiVersion(); } bool TestLatLon(int index, double lat, double lon) const { - double tLat, tLon; - GetMark(index)->GetLatLon(tLat, tLon); - return my::AlmostEqualULPs(tLat, lat) && my::AlmostEqualULPs(tLon, lon); + ms::LatLon const ll = GetMark(index)->GetLatLon(); + return my::AlmostEqualULPs(ll.lat, lat) && my::AlmostEqualULPs(ll.lon, lon); } bool TestName(int index, string const & name) const diff --git a/map/user_mark.cpp b/map/user_mark.cpp index d1f935eb6a..852fe28e08 100644 --- a/map/user_mark.cpp +++ b/map/user_mark.cpp @@ -56,18 +56,16 @@ UserMarkContainer const * UserMark::GetContainer() const return m_container; } -void UserMark::GetLatLon(double & lat, double & lon) const +ms::LatLon UserMark::GetLatLon() const { - lon = MercatorBounds::XToLon(m_ptOrg.x); - lat = MercatorBounds::YToLat(m_ptOrg.y); + return MercatorBounds::ToLatLon(m_ptOrg); } void UserMark::FillLogEvent(UserMark::TEventContainer & details) const { - double lat, lon; - GetLatLon(lat, lon); - details.emplace("lat", strings::to_string(lat)); - details.emplace("lon", strings::to_string(lon)); + ms::LatLon const ll = GetLatLon(); + details.emplace("lat", strings::to_string(ll.lat)); + details.emplace("lon", strings::to_string(ll.lon)); details.emplace("markType", ToString(GetMarkType())); } diff --git a/map/user_mark.hpp b/map/user_mark.hpp index d9948a0703..b1a5701a60 100644 --- a/map/user_mark.hpp +++ b/map/user_mark.hpp @@ -6,6 +6,7 @@ #include "indexer/feature.hpp" +#include "geometry/latlon.hpp" #include "geometry/point2d.hpp" #include "base/macros.hpp" @@ -46,7 +47,7 @@ public: /////////////////////////////////////////////////////// UserMarkContainer const * GetContainer() const; - void GetLatLon(double & lat, double & lon) const; + ms::LatLon GetLatLon() const; virtual Type GetMarkType() const = 0; virtual unique_ptr Copy() const = 0; // Need it to calculate POI rank from all taps to features via statistics.