mapbox-maps-ios icon indicating copy to clipboard operation
mapbox-maps-ios copied to clipboard

Conversion of point to map's coordinate is slightly off between v6 and v10

Open LearnWithTung opened this issue 3 years ago • 1 comments

Environment

  • Xcode version: 13.2.1
  • iOS version: 15.2
  • Devices affected: simulator and devices
  • Maps SDK Version: 10.2.0

Observed behavior and steps to reproduce

I'm having this setup in v6 to get the viewport from map's bounds

    let mapSize = self.bounds
    let topRightPoint = CGPoint(x: mapSize.maxX, y: mapSize.minY)
    let topRight = self.convert(topRightPoint, toCoordinateFrom: self)

    let topLeftPoint = CGPoint(x: mapSize.minX, y: mapSize.minY)
    let topLeft = self.convert(topLeftPoint, toCoordinateFrom: self)

    let bottomLeftPoint = CGPoint(x: mapSize.minX, y: mapSize.maxY)
    let bottomLeft = self.convert(bottomLeftPoint, toCoordinateFrom: self)

    let bottomRightPoint = CGPoint(x: mapSize.maxX, y: mapSize.maxY)
    let bottomRight = self.convert(bottomRightPoint, toCoordinateFrom: self)

    let centerPoint = CGPoint(x: mapSize.midX, y: mapSize.midY)
    let center = self.convert(centerPoint, toCoordinateFrom: self)
    
    return Viewport(center: center, topLeft: topLeft, topRight: topRight, bottomRight: bottomRight, bottomLeft: bottomLeft, zoomLevel: zoomLevel)

I'm trying to migrate it to v10 like bellow

    let mapSize = self.bounds
    let topRightPoint = CGPoint(x: mapSize.maxX, y: mapSize.minY)
    let topRight = mapboxMap.coordinate(for: topRightPoint)

    let topLeftPoint = CGPoint(x: mapSize.minX, y: mapSize.minY)
    let topLeft = mapboxMap.coordinate(for: topLeftPoint)

    let bottomLeftPoint = CGPoint(x: mapSize.minX, y: mapSize.maxY)
    let bottomLeft = mapboxMap.coordinate(for: bottomLeftPoint)

    let bottomRightPoint = CGPoint(x: mapSize.maxX, y: mapSize.maxY)
    let bottomRight = mapboxMap.coordinate(for: bottomRightPoint)

    let centerPoint = CGPoint(x: mapSize.midX, y: mapSize.midY)
    let center = self.mapboxMap.coordinate(for: centerPoint)

    return Viewport(center: center, topLeft: topLeft, topRight: topRight, bottomRight: bottomRight, bottomLeft: bottomLeft, zoomLevel: zoomLevel)

But they are return the different results. In term of coordinate it's a big different and impact the result Here's an example of results. From v6

    let center = CLLocationCoordinate2D(latitude: 51.50852749999882, longitude: -0.11690900001943305)
    let topLeft = CLLocationCoordinate2D(latitude: 51.51029813371716, longitude: -0.11847939158212739)
    let topRight = CLLocationCoordinate2D(latitude: 51.51029813371716, longitude: -0.11533860845673871)
    let bottomRight = CLLocationCoordinate2D(latitude: 51.506756797466124, longitude: -0.11533860845673871)
    let bottomLeft = CLLocationCoordinate2D(latitude: 51.506756797466124, longitude:  -0.11847939158212739)

From v10

    let center = CLLocationCoordinate2D(latitude: 51.50852750000044, longitude: -0.11690900000149895)
    let topLeft = CLLocationCoordinate2D(latitude: 51.51024311546047, longitude: -0.11843059443560833)
    let topRight = CLLocationCoordinate2D(latitude: 51.51027493029375, longitude: -0.11535918816787216)
    let bottomRight = CLLocationCoordinate2D(latitude: 51.50677690990716, longitude: -0.1153564453125)
    let bottomLeft = CLLocationCoordinate2D(latitude: 51.50676052129944, longitude:  -0.11847608905304696)

Expected behavior

Result should be the same in both setup

LearnWithTung avatar Jan 20 '22 10:01 LearnWithTung

@LearnWithTung, thank you for reporting this behavior. I am able to reproduce with v10.2.0.

ZiZasaurus avatar Jan 20 '22 15:01 ZiZasaurus