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

Allow plugins to transform location updates #12280

Closed

Description

@1ec5

The iOS map SDK needs to support a new plugin that performs a transformation on each location update that comes from the location manager to a specific geodetic datum, by registering an NSValueTransformer. Some corresponding changes are needed in the iOS map SDK to support this plugin:

  • Define a value transformer name as a constant, such as MGLConvertToDatumTransformerName.
  • Use the value transformer whenever we position the user dot or camera in response to a user location update.

This would be a lightweight complement to the custom location manager API being implemented in #12013. It would only be appropriate for certain use cases requiring a different datum. This feature is not intended to introduce support for alternative map projections.

As an alternative to consulting a value transformer, support for this plugin could be provided through a custom MGLLocationManager implementation based on #12013. However, that would require the plugin to configure a new CLLocationManager independently of the configuration that’s currently built into the map SDK.

/cc @lloydsheng @fabian-guerra @julianrex

Activity

  1. added
    iOS
    on Jul 2, 2018
  2. julianrex commented on Jul 2, 2018

    @julianrex
    Contributor

    I like the idea of providing a transformer - though perhaps this should be defined by a protocol?

  3. fabian-guerra commented on Jul 2, 2018

    @fabian-guerra
    Contributor

    Are you thinking about the SDK provide a default datum converter? The advantage of the new location manager api is that you can account for correcting location offsets or perform a transformation as long as you pass the update to the LM delegate.

    As an example look at this lines:

    - (void)updateLocation
    {
    if ([self.delegate respondsToSelector:@selector(locationManager:didUpdateLocations:)]) {
    if (self.index >= [self.coordinates count] ) {
    self.index = 0;
    self.coordinates = [[self.coordinates reverseObjectEnumerator] allObjects];
    }
    NSArray *loc = self.coordinates[self.index];
    CLLocationDegrees latitude = [[loc objectAtIndex:1] doubleValue];
    CLLocationDegrees longitude = [[loc objectAtIndex:0] doubleValue];
    CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
    self.index++;
    [self.delegate locationManager:self didUpdateLocations:@[location]];
    }
    }

    If the case is provide a default converter then I agree with @julianrex that this could be a protocol, but then we open the door to provide multiple conversions or at least one.

  4. 1ec5 commented on Jul 2, 2018

    @1ec5
    ContributorAuthor

    NSValueTransformer would allow us to support this plugin rather transparently. The plugin would run this code at initialization:

    [NSValueTransformer setValueTransformer:[[CoordinateTransformer alloc] init] forName:@"MGLConvertToDatumTransformerName"];

    and -[CoordinateTransformer transformedValue:] would get called at the appropriate times.

    NSValueTransformer would have limited capabilities compared to a protocol such as MGLLocationManager. For example, a value transformer probably has to be stateless, unlike a custom MGLLocationManager implementation. On the other hand, a value transformer has the benefit of inheriting all the built-in location manager’s settings. That’s appropriate for datum conversion, which is orthogonal to those settings.

  5. self-assigned this
    on Jul 6, 2018
  6. 1ec5 commented on Jul 12, 2018

    @1ec5
    ContributorAuthor

    @fabian-guerra, I think we need to implement this change regardless of #12013. An application may need to install the plugin described above and implement their own custom location manager for things like indoor positioning. The map view would transform the location manager’s updates, whether built-in or custom, before using them to position the camera or user location annotation. It’s also conceivable that the plugin would expand to handle overlay data in the future, in which case the registered value transformer could also come in handy.

  7. fabian-guerra commented on Aug 20, 2018

    @fabian-guerra
    Contributor

    This was addressed in the China plugin repo. The plugin creates a LM with coordinates conversion and implements the NSValueTransformer.

  8. 1ec5 commented on Aug 21, 2018

    @1ec5
    ContributorAuthor

    As I pointed out in #12280 (comment), this means users of the plugin are unable to implement their own custom location managers for purposes like indoor location tracking or location simulation. The plugin will need to expose its own custom custom location manager interface for this purpose.

    /cc @lloydsheng

  9. fabian-guerra commented on Aug 21, 2018

    @fabian-guerra
    Contributor

    Elaborating more into the final implementation:

    • The China plugin has a public MBCNLocationManager. I made it public but forgot to add it to the header. This has been fixed.
    • For cases where there is a need for custom location tracking such as indoor or location simulation the value transformer can be used (since indoor LM require calibration it's possible they already deliver the coordinates in the appropriate system).

    /cc @lloydsheng @1ec5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

featureiOS

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions