Search code examples
swiftgoogle-maps-sdk-ios

Find markers shown in mapView


I am trying to determine the marker/s currently shown in a mapview. I have researched the following the method:

self.mapView.bounds.contains(markers[0].position)

But the contains command accepts CGPoint or CGRect. In other platforms except Swift, contains can accept the marker's position.

How do I convert the marker's position to be accepted by contains?


Solution

  • Use the mapview's current projection. Use the projection's method called containsCoordinate to check if you marker's position is inside the projection, i.e. currently visible.

    So something like:

    let coord = marker.position
    let isVisible = self.mapview.projection.containsCoordinate(coord)
    

    https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_projection.html#aa6ad29e6831e40f00435c3aaeda8e08a