mapbox / mapbox/mapbox-maps-ios

I need the initial center latitude and longitude for the map view after loading markers in swiftUI.

Open
#2,182 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle: question
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?

Screenshot 2024-05-16 at 6 39 13 PM

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.