From 754ba7c139ed3be1ef108f8118b0fc50ec57b88e Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Mon, 13 Dec 2010 12:09:52 +0000 Subject: [PATCH] Closes #77 [iPhone] Enable/Disable GPS switching --- iphone/Maps/Classes/MapViewController.mm | 29 +++++++++---------- .../Maps/Classes/UserLocationController.hpp | 15 ++-------- iphone/Maps/Classes/UserLocationController.mm | 7 +++-- map/framework.hpp | 8 +++++ 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 7c6578fb0e..6c506a623a 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -10,9 +10,6 @@ #include "../../map/drawer_yg.hpp" #include "../../map/storage.hpp" -/// Location service will stop only when received lat long will be earlier than this value -#define MAX_SECONDS_INTERVAL_FOR_RECENT_LOCATION 60.0 - typedef FrameWork framework_t; @implementation MapViewController @@ -22,9 +19,18 @@ typedef FrameWork frame - (void) OnMyPositionClicked: (id)sender { - [m_locationController Stop]; - [m_locationController Start]; - m_isDirtyPosition = true; + if (m_locationController.active) + { + [m_locationController Stop]; + ((UIBarItem *)sender).title = @"My Position"; + m_framework->DisableMyPositionAndHeading(); + } + else + { + [m_locationController Start]; + m_isDirtyPosition = true; + ((UIBarItem *)sender).title = @"Disable GPS"; + } } - (void) OnSettingsClicked: (id)sender @@ -74,22 +80,13 @@ typedef FrameWork frame - (void) OnHeading: (double) heading withTimestamp: (NSDate *)timestamp { - NSTimeInterval secondsFromLastUpdate = [timestamp timeIntervalSinceNow]; - if (fabs(secondsFromLastUpdate)< MAX_SECONDS_INTERVAL_FOR_RECENT_LOCATION) - [m_locationController Stop]; m_framework->SetHeading(heading); } - - (void) OnLocation: (m2::PointD const &) mercatorPoint -withConfidenceRadius: (double) confidenceRadius + withConfidenceRadius: (double) confidenceRadius withTimestamp: (NSDate *) timestamp { - // stop location update to preserve battery, but only if received location is up to date - NSTimeInterval secondsFromLastUpdate = [timestamp timeIntervalSinceNow]; - if (fabs(secondsFromLastUpdate) < MAX_SECONDS_INTERVAL_FOR_RECENT_LOCATION) - [m_locationController Stop]; - m_framework->SetPosition(mercatorPoint, confidenceRadius); if (m_isDirtyPosition) diff --git a/iphone/Maps/Classes/UserLocationController.hpp b/iphone/Maps/Classes/UserLocationController.hpp index 67b30d502d..947785157b 100644 --- a/iphone/Maps/Classes/UserLocationController.hpp +++ b/iphone/Maps/Classes/UserLocationController.hpp @@ -21,24 +21,15 @@ withConfidenceRadius: (double) confidenceRadius @public id delegate; + BOOL active; } @property (nonatomic, assign) id delegate; +/// YES means that location manager is active +@property (nonatomic, assign) BOOL active; - (id) initWithDelegate: (id) locationDelegate; - - (void) Start; - - (void) Stop; -- (void) locationManager: (CLLocationManager *) manager - didUpdateToLocation: (CLLocation *) newLocation - fromLocation: (CLLocation *) oldLocation; - -- (void) locationManager: (CLLocationManager *) manager - didUpdateHeading: (CLHeading *) newHeading; - -- (void) locationManager: (CLLocationManager *) manager - didFailWithError: (NSError *) error; - @end diff --git a/iphone/Maps/Classes/UserLocationController.mm b/iphone/Maps/Classes/UserLocationController.mm index 01830938d9..77d48fceb8 100644 --- a/iphone/Maps/Classes/UserLocationController.mm +++ b/iphone/Maps/Classes/UserLocationController.mm @@ -5,6 +5,7 @@ @implementation UserLocationController @synthesize delegate; +@synthesize active; - (id) init { @@ -13,6 +14,7 @@ { m_locationManager = [[CLLocationManager alloc] init]; m_locationManager.delegate = self; + active = NO; } return self; } @@ -32,8 +34,7 @@ - (void) Start { - - + active = YES; [m_locationManager startUpdatingLocation]; if ([m_locationManager headingAvailable]) { @@ -42,13 +43,13 @@ } else NSLog(@"heading information is not available"); - } - (void) Stop { [m_locationManager stopUpdatingLocation]; [m_locationManager stopUpdatingHeading]; + active = NO; } - (void) locationManager: (CLLocationManager *) manager diff --git a/map/framework.hpp b/map/framework.hpp index b3a0d6cd49..a93c48145b 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -385,6 +385,14 @@ public: } } + void DisableMyPositionAndHeading() + { + m_isPositionEnabled = false; + m_isHeadingEnabled = false; + + UpdateNow(); + } + void SetPosition(m2::PointD const & mercatorPos, double confidenceRadius) { m_isPositionEnabled = true;