diff options
author | Alex Zolotarev <deathbaba@gmail.com> | 2011-11-15 21:41:32 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:28:03 +0300 |
commit | fe1c07f091dc9dfb7f5adda8a6569d729c1baebc (patch) | |
tree | d0806347d730c28aeb5ba4819b93af91cccda801 | |
parent | c47199b2295a7969b4c49c24606474fae346a127 (diff) |
Closed #347 - check for invalid rect and location
-rw-r--r-- | iphone/Maps/Platform/LocationManager.mm | 20 | ||||
-rw-r--r-- | map/framework.cpp | 5 | ||||
-rw-r--r-- | map/navigator.cpp | 6 | ||||
-rw-r--r-- | platform/location.hpp | 10 | ||||
-rw-r--r-- | platform/wifi_location_service.cpp | 15 |
5 files changed, 38 insertions, 18 deletions
diff --git a/iphone/Maps/Platform/LocationManager.mm b/iphone/Maps/Platform/LocationManager.mm index a388df04d7..c6958d8f0c 100644 --- a/iphone/Maps/Platform/LocationManager.mm +++ b/iphone/Maps/Platform/LocationManager.mm @@ -94,17 +94,21 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { - if (m_reportFirstUpdate) + if (location::IsLatValid(newLocation.coordinate.latitude) + && location::IsLonValid(newLocation.coordinate.longitude)) { + if (m_reportFirstUpdate) + { + for (id observer in m_observers) + [observer onLocationStatusChanged:location::EFirstEvent]; + m_reportFirstUpdate = NO; + } + + location::GpsInfo newInfo; + [self location:newLocation toGpsInfo:newInfo]; for (id observer in m_observers) - [observer onLocationStatusChanged:location::EFirstEvent]; - m_reportFirstUpdate = NO; + [observer onGpsUpdate:newInfo]; } - - location::GpsInfo newInfo; - [self location:newLocation toGpsInfo:newInfo]; - for (id observer in m_observers) - [observer onGpsUpdate:newInfo]; } - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading diff --git a/map/framework.cpp b/map/framework.cpp index 44661e2dc1..85304abedf 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -217,10 +217,7 @@ void Framework<TModel>::SaveState() template <typename TModel> bool Framework<TModel>::LoadState() { - if (!m_navigator.LoadState()) - return false; - - return true; + return m_navigator.LoadState(); } //@} diff --git a/map/navigator.cpp b/map/navigator.cpp index 232ea36510..5ddf298341 100644 --- a/map/navigator.cpp +++ b/map/navigator.cpp @@ -76,6 +76,12 @@ bool Navigator::LoadState() if (!Settings::Get("ScreenClipRect", rect)) return false; + // additional check for valid rect + m2::RectD const r = rect.GetGlobalRect(); + if (r.minX() < MercatorBounds::minX || r.minY() < MercatorBounds::minY + || r.maxX() > MercatorBounds::maxX || r.maxY() > MercatorBounds::maxY) + return false; + SetFromRect(rect); return true; } diff --git a/platform/location.hpp b/platform/location.hpp index 7342298854..5080acaeaf 100644 --- a/platform/location.hpp +++ b/platform/location.hpp @@ -52,4 +52,14 @@ namespace location // int m_y; // int m_z; }; + + static inline bool IsLatValid(double lat) + { + return lat != 0. && lat < 90. && lat > -90.; + } + static inline bool IsLonValid(double lon) + { + return lon != 0. && lon < 180. && lon > -180.; + } + } // namespace location diff --git a/platform/wifi_location_service.cpp b/platform/wifi_location_service.cpp index 9e7ceedfd7..dfd6beecf9 100644 --- a/platform/wifi_location_service.cpp +++ b/platform/wifi_location_service.cpp @@ -42,12 +42,15 @@ namespace location GpsInfo info; info.m_latitude = json_real_value(lat); info.m_longitude = json_real_value(lon); - info.m_horizontalAccuracy = json_real_value(acc); - // @TODO introduce flags to mark valid values - info.m_timestamp = static_cast<double>(time(NULL)); - info.m_source = location::EGoogle; - m_observer.OnGpsUpdated(info); - success = true; + if (IsLatValid(info.m_latitude) && IsLonValid(info.m_latitude)) + { + info.m_horizontalAccuracy = json_real_value(acc); + // @TODO introduce flags to mark valid values + info.m_timestamp = static_cast<double>(time(NULL)); + info.m_source = location::EGoogle; + m_observer.OnGpsUpdated(info); + success = true; + } } } } |