Skip to content

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

Open
@KishoreZuper

Description

@KishoreZuper

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🪲Something is broken!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions