mapbox / mapbox/mapbox-maps-ios
I need the initial center latitude and longitude for the map view after loading markers in swiftUI.
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 601
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
## Environment
- Xcode version: 15.0
- iOS version: 17
- Devices affected:
- Maps SDK Version: 11.3.0
## Observed behavior and steps to reproduce
I'm planning to implement a "Search this area" functionality. Here's how it will work: as the user scrolls the map and the center point changes, the system will compare the initial center point with the current point to determine if the distance exceeds a certain threshold. If it does, the option to 'Search this place' will be displayed.
However, in this scenario, I'm facing difficulty finding the initial map view's center latitude and longitude. I'm currently using ".overview" to display all the markers.
## Expected behavior
After loading the map, I'm able to obtain the center point for the map view.
## Notes / preliminary analysis
`withViewportAnimation(.fly(duration: 2)) {
viewport = .overview(geometry: multiPoints, geometryPadding: EdgeInsets(top: 50, leading: 20, bottom: screenHeight * 0.4, trailing: 20), maxZoom: zoom, offset: .zero)
}`
I'm using the "`viewport`" method to show the markers on the map view. Because of this, I cannot get the center location of the map since this method does not set any center. Is there an alternate way to get the initial center location or if we `.overview` where the center will be set and how to access it?
If the map moves, I can get the new center location by using "onCameraChanged(action:)". In the way, if I get the initial map location, I can find the distance and call the API.
## Additional links and references
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the SwiftUI map code using viewport, especially the .overview geometry and withViewportAnimation call, and compare it with the onCameraChanged(action:) callback that reports later movement. Determine how the initial center after loading markers can be obtained, then verify that it supports comparing the initial and current points for the planned search-area behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100