forked from organicmaps/organicmaps-tmp
parent
80e9f2477c
commit
754ba7c139
4 changed files with 28 additions and 31 deletions
|
@ -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<model::FeaturesFetcher, Navigator, iphone::WindowHandle> framework_t;
|
||||
|
||||
@implementation MapViewController
|
||||
|
@ -22,9 +19,18 @@ typedef FrameWork<model::FeaturesFetcher, Navigator, iphone::WindowHandle> 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<model::FeaturesFetcher, Navigator, iphone::WindowHandle> 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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue