Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios] MGLMapView update to new location manager API.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-guerra committed Jun 1, 2018
1 parent e18c8ea commit 4891635
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
7 changes: 7 additions & 0 deletions platform/darwin/src/MGLLocationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ - (void)stopUpdatingLocation
[self.locationManager stopUpdatingLocation];
}

- (void)dealloc
{
[self.locationManager stopUpdatingLocation];
[self.locationManager stopUpdatingHeading];
self.delegate = nil;
}

#pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
Expand Down
5 changes: 3 additions & 2 deletions platform/ios/ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2658,6 +2658,7 @@
};
DA1DC9491CB6C1C2006E619F = {
CreatedOnToolsVersion = 7.3;
DevelopmentTeam = 26847786Y6;
LastSwiftMigration = 0820;
};
DA25D5B81CCD9EDE00607828 = {
Expand Down Expand Up @@ -3628,7 +3629,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 26847786Y6;
INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL;
Expand All @@ -3641,7 +3642,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 26847786Y6;
INFOPLIST_FILE = "$(SRCROOT)/app/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL;
Expand Down
4 changes: 3 additions & 1 deletion platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#import "MGLMapCamera.h"

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

#import "MGLFoundation.h"
#import "MGLTypes.h"
Expand All @@ -22,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
@protocol MGLOverlay;
@protocol MGLCalloutView;
@protocol MGLFeature;
@protocol MGLLocationManager;

/** The default deceleration rate for a map view. */
extern MGL_EXPORT const CGFloat MGLMapViewDecelerationRateNormal;
Expand Down Expand Up @@ -296,6 +296,8 @@ MGL_EXPORT IB_DESIGNABLE

#pragma mark Displaying the User’s Location

@property (nonatomic, nullable) id<MGLLocationManager> locationManager;

/**
A Boolean value indicating whether the map may display the user location.
Expand Down
17 changes: 12 additions & 5 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#import "MGLAnnotationContainerView_Private.h"
#import "MGLAttributionInfo_Private.h"
#import "MGLMapAccessibilityElement.h"
#import "MGLLocationManager_Private.h"

#include <algorithm>
#include <cstdlib>
Expand Down Expand Up @@ -184,7 +185,7 @@ typedef NS_ENUM(NSUInteger, MGLUserTrackingState) {

@interface MGLMapView () <UIGestureRecognizerDelegate,
GLKViewDelegate,
CLLocationManagerDelegate,
MGLLocationManagerDelegate,
MGLSMCalloutViewDelegate,
MGLCalloutViewDelegate,
MGLMultiPointDelegate,
Expand Down Expand Up @@ -225,7 +226,6 @@ @interface MGLMapView () <UIGestureRecognizerDelegate,

/// Indicates how thoroughly the map view is tracking the user location.
@property (nonatomic) MGLUserTrackingState userTrackingState;
@property (nonatomic) CLLocationManager *locationManager;
@property (nonatomic) CGFloat scale;
@property (nonatomic) CGFloat angle;
@property (nonatomic) CGFloat quickZoomStart;
Expand Down Expand Up @@ -4680,13 +4680,20 @@ - (void)applyIconIdentifier:(NSString *)iconIdentifier toAnnotationsWithImageReu

#pragma mark - User Location -

- (void)setLocationManager:(id<MGLLocationManager>)locationManager
{
_locationManager = locationManager;
_locationManager.delegate = self;
[self validateLocationServices];
}

- (void)validateLocationServices
{
BOOL shouldEnableLocationServices = self.showsUserLocation && !self.dormant;

if (shouldEnableLocationServices && ! self.locationManager)
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager = [[MGLCLLocationManager alloc] init];

if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
{
Expand Down Expand Up @@ -4959,12 +4966,12 @@ - (void)validateUserHeadingUpdating
}
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
- (void)locationManager:(MGLCLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
[self locationManager:manager didUpdateLocations:locations animated:YES];
}

- (void)locationManager:(__unused CLLocationManager *)manager didUpdateLocations:(NSArray *)locations animated:(BOOL)animated
- (void)locationManager:(__unused MGLCLLocationManager *)manager didUpdateLocations:(NSArray *)locations animated:(BOOL)animated
{
CLLocation *oldLocation = self.userLocation.location;
CLLocation *newLocation = locations.lastObject;
Expand Down

0 comments on commit 4891635

Please sign in to comment.