Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KishoreZuper opened this issue May 13, 2024 · 2 comments
Labels
bug 🪲 Something is broken!

Comments

@KishoreZuper
Copy link

KishoreZuper commented May 13, 2024

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

@KishoreZuper KishoreZuper added the bug 🪲 Something is broken! label May 13, 2024
@maios
Copy link
Contributor

maios commented May 14, 2024

Hi @KishoreZuper, have you tried with MapboxMap/cameraState
More links:
-Get Camera position

@KishoreZuper
Copy link
Author

Hi @maios, I updated my comments. Can you look at them? I added more information about my issue. Thanks for your reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something is broken!
Projects
None yet
Development

No branches or pull requests

2 participants