mapbox / mapbox/mapbox-maps-ios

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

Open
#1,043 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
Dominant language
Swift
Stars
601
Forks
196
PR merge metrics
No merged PRs in 30d

Description

## 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the v6 conversion calls with the v10 `mapboxMap.coordinate(for:)` entry point using the reproduction coordinates and device details in the report. Investigate why corner coordinates differ, then verify that the center and viewport corners match the expected v6 results across the listed simulator and device environments.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.