diff options
author | Ian Wagner <ianthetechie@gmail.com> | 2017-07-27 22:28:41 -0400 |
---|---|---|
committer | Jason Wray <jason@mapbox.com> | 2017-08-28 16:41:55 -0400 |
commit | e78620c70567a995a6f02ae3ee85cc5dd7f3fade (patch) | |
tree | 118305aa043981d933474084fa73f44f2909d24a /platform/ios/src | |
parent | a7f06366d2c431bdf34fcfa14314be43ac09987b (diff) | |
download | qtlocation-mapboxgl-e78620c70567a995a6f02ae3ee85cc5dd7f3fade.tar.gz |
[ios] Set location to nil until the user's location is determined
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.
Diffstat (limited to 'platform/ios/src')
-rw-r--r-- | platform/ios/src/MGLUserLocation.h | 3 | ||||
-rw-r--r-- | platform/ios/src/MGLUserLocation.m | 3 |
2 files changed, 2 insertions, 4 deletions
diff --git a/platform/ios/src/MGLUserLocation.h b/platform/ios/src/MGLUserLocation.h index 8c6fe46136..91abadbcb7 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 1c9649c09e..074d138a72 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 |