fixed Locator logic. made location services switchable.

This commit is contained in:
rachytski 2011-04-16 14:57:55 +03:00 committed by Alex Zolotarev
parent 54d816abac
commit c87ed94fbc
6 changed files with 76 additions and 51 deletions

View file

@ -21,10 +21,10 @@ typedef FrameWork<model::FeaturesFetcher, Navigator> framework_t;
@synthesize m_iconTimer;
@synthesize m_iconSequenceNumber;
// @TODO Make m_framework and m_storage MapsAppDelegate properties instead of global variables.
framework_t * m_framework = NULL;
shared_ptr<Locator> m_locator;
storage::Storage m_storage;
// @TODO Make m_framework and m_storage MapsAppDelegate properties instead of global variables.
framework_t * m_framework = NULL;
shared_ptr<Locator> m_locator;
storage::Storage m_storage;
- (void) ZoomToRect: (m2::RectD const &) rect
{
@ -55,28 +55,21 @@ typedef FrameWork<model::FeaturesFetcher, Navigator> framework_t;
- (IBAction)OnMyPositionClicked:(id)sender
{
if (m_locator->mode() == Locator::EPreciseMode)
{
m_locator->setMode(Locator::ERoughMode);
((UIBarButtonItem *)sender).style = UIBarButtonItemStyleBordered;
}
else
{
m_locator->setMode(Locator::EPreciseMode);
m_isDirtyPosition = true;
if (m_locator->isRunning())
{
m_locator->stop();
m_framework->StopLocator();
((UIBarButtonItem*) sender).style = UIBarButtonItemStyleBordered;
}
else
{
m_framework->StartLocator(Locator::EPreciseMode);
m_locator->start(Locator::EPreciseMode);
m_isDirtyPosition = true;
((UIBarButtonItem *)sender).style = UIBarButtonItemStyleDone;
/* m_iconSequenceNumber = 0;
m_iconTimer = [NSTimer scheduledTimerWithTimeInterval:0.1f
target:self
selector:@selector(UpdateIcon:)
userInfo:nil
repeats:NO];
NSLog(@"IconTimerStart");*/
((UIBarButtonItem *)sender).image = [UIImage imageNamed:@"location-search.png"];
}
((UIBarButtonItem*)sender).style = UIBarButtonItemStyleDone;
((UIBarButtonItem*)sender).image = [UIImage imageNamed:@"location-search.png"];
}
}
- (void) OnChangeLocatorMode:(Locator::EMode) oldMode
@ -84,14 +77,8 @@ typedef FrameWork<model::FeaturesFetcher, Navigator> framework_t;
{
if (newMode == Locator::ERoughMode)
{
/* if (m_iconTimer != nil)
{
[m_iconTimer invalidate];
m_iconTimer = nil;
}
*/
m_myPositionButton.image = [UIImage imageNamed:@"location.png"];
m_myPositionButton.style = UIBarButtonItemStyleBordered;
// m_myPositionButton.style = UIBarButtonItemStyleBordered;
}
}

View file

@ -28,15 +28,16 @@
- (void) dealloc
{
[self Stop];
// [self Stop];
[self.locationManager release];
[super dealloc];
}
- (void) Start
/*- (void) Start
{
// active = YES;
[self.locationManager startUpdatingLocation];
self.locationManager.distanceFilter = kCLDistanceFilterNone;
if ([CLLocationManager headingAvailable])
{
self.locationManager.headingFilter = 1;
@ -51,7 +52,7 @@
[self.locationManager stopUpdatingLocation];
[self.locationManager stopUpdatingHeading];
// active = NO;
}
}*/
- (void) locationManager: (CLLocationManager *) manager
didUpdateHeading: (CLHeading *) newHeading

View file

@ -62,25 +62,27 @@ namespace iphone
{
::Locator::setMode(mode);
[m_locationController.locationManager startUpdatingLocation];
if (mode == ERoughMode)
[m_locationController.locationManager startMonitoringSignificantLocationChanges];
m_locationController.locationManager.distanceFilter = 100;
else
[m_locationController.locationManager startUpdatingLocation];
m_locationController.locationManager.distanceFilter = kCLDistanceFilterNone;
if ([CLLocationManager headingAvailable])
{
m_locationController.locationManager.headingFilter = 1;
[m_locationController.locationManager startUpdatingHeading];
}
::Locator::start(mode);
}
void Locator::stop()
{
if (mode() == ERoughMode)
[m_locationController.locationManager stopMonitoringSignificantLocationChanges];
else
[m_locationController.locationManager stopUpdatingLocation];
::Locator::stop();
[m_locationController.locationManager stopUpdatingLocation];
if ([CLLocationManager headingAvailable])
[m_locationController.locationManager stopUpdatingHeading];
}
@ -92,15 +94,9 @@ namespace iphone
callOnChangeModeFns(oldMode, mode);
if (mode == ERoughMode)
{
[m_locationController.locationManager stopUpdatingLocation];
[m_locationController.locationManager startMonitoringSignificantLocationChanges];
}
m_locationController.locationManager.distanceFilter = 100;
else
{
[m_locationController.locationManager stopMonitoringSignificantLocationChanges];
[m_locationController.locationManager startUpdatingLocation];
}
m_locationController.locationManager.distanceFilter = kCLDistanceFilterNone;
}
void Locator::locationUpdate(m2::PointD const & pt, double errorRadius, double locTimeStamp, double curTimeStamp)

View file

@ -250,8 +250,22 @@ public:
m_locator->addOnUpdateLocationFn(bind(&this_type::UpdateLocation, this, _1, _2, _3, _4));
m_locator->addOnUpdateHeadingFn(bind(&this_type::UpdateHeading, this, _1, _2, _3));
m_locator->addOnChangeModeFn(bind(&this_type::ChangeLocatorMode, this, _1, _2));
m_locator->start(Locator::ERoughMode);
// m_locator->start(Locator::ERoughMode);
}
void StartLocator(Locator::EMode mode)
{
if (mode == Locator::EPreciseMode)
m_doCenterViewport = true;
}
void StopLocator()
{
m_informationDisplay.enablePosition(false);
m_doCenterViewport = false;
Invalidate();
}
bool IsEmptyModel()
{

View file

@ -1,6 +1,12 @@
#include "../base/SRC_FIRST.hpp"
#include "locator.hpp"
Locator::Locator() : m_isRunning(false)
{}
Locator::~Locator()
{}
void Locator::setMode(EMode mode)
{
m_mode = mode;
@ -11,6 +17,21 @@ Locator::EMode Locator::mode() const
return m_mode;
}
void Locator::start(Locator::EMode /*mode*/)
{
m_isRunning = true;
}
void Locator::stop()
{
m_isRunning = false;
}
bool Locator::isRunning() const
{
return m_isRunning;
}
void Locator::callOnChangeModeFns(EMode oldMode, EMode newMode)
{
list<onChangeModeFn> handlers = m_onChangeModeFns;

View file

@ -27,8 +27,14 @@ private:
EMode m_mode;
bool m_isRunning;
public:
Locator();
virtual ~Locator();
bool isRunning() const;
virtual void start(EMode mode) = 0;
virtual void stop() = 0;
virtual void setMode(EMode mode) = 0;