From e78620c70567a995a6f02ae3ee85cc5dd7f3fade Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Thu, 27 Jul 2017 22:28:41 -0400 Subject: [PATCH] [ios] Set location to nil until the user's location is determined MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The documentation for the `location` property states that "This property contains `nil` if the map view is not currently showing the user location or if the user’s location has not yet been determined." The iOS SDK presently returns a garbage value, which has some rather annoying consequences when the value should logically be nullable. This change should rectify the issue. With _location no longer initialized to an invalid coordinate, trying to access `_location.coordinate` when `_location == nil` will return `0, 0`, which is a valid coordinate. --- platform/ios/CHANGELOG.md | 1 + platform/ios/src/MGLUserLocation.h | 3 +-- platform/ios/src/MGLUserLocation.m | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index d8267092d..a1d880803 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT * Fixed an issue where user heading tracking mode would update too frequently. ([#9845](https://github.com/mapbox/mapbox-gl-native/pull/9845)) * Added support for iOS 11 location usage descriptions. ([#9869](https://github.com/mapbox/mapbox-gl-native/pull/9869)) +* Fixed an issue where `MGLUserLocation.location` did not follow its documented initialization behavior. This property will now properly return `nil` until the user’s location has been determined. ([#9639](https://github.com/mapbox/mapbox-gl-native/pull/9639)) ## 3.6.2 - August 18, 2017 diff --git a/platform/ios/src/MGLUserLocation.h b/platform/ios/src/MGLUserLocation.h index 8c6fe4613..91abadbcb 100644 --- a/platform/ios/src/MGLUserLocation.h +++ b/platform/ios/src/MGLUserLocation.h @@ -20,8 +20,7 @@ MGL_EXPORT /** The current location of the device. (read-only) - This property contains `nil` if the map view is not currently showing the user - location or if the user’s location has not yet been determined. + This property returns `nil` if the user’s location has not yet been determined. */ @property (nonatomic, readonly, nullable) CLLocation *location; diff --git a/platform/ios/src/MGLUserLocation.m b/platform/ios/src/MGLUserLocation.m index 1c9649c09..074d138a7 100644 --- a/platform/ios/src/MGLUserLocation.m +++ b/platform/ios/src/MGLUserLocation.m @@ -19,7 +19,6 @@ NS_ASSUME_NONNULL_END { if (self = [super init]) { - _location = [[CLLocation alloc] initWithLatitude:MAXFLOAT longitude:MAXFLOAT]; _mapView = mapView; } @@ -102,7 +101,7 @@ NS_ASSUME_NONNULL_END - (CLLocationCoordinate2D)coordinate { - return self.location.coordinate; + return _location ? _location.coordinate : kCLLocationCoordinate2DInvalid; } - (NSString *)title