2

I want to animate to a specific location while showing all the markers i have pinned on Google map .

I am able to animate to a location but it is not showing all the markers.

I have tried the following solution (answer link) .

I am calling hover(to location:) for each location i want to animate:

func viewAllMarkers() {
  var bounds = GMSCoordinateBounds()
  for marker in yourArrayOfMarkers {
        bounds = bounds.includingCoordinate(marker.position)
  }
  let update = GMSCameraUpdate.fit(bounds, withPadding: 60)
  mapView.animate(with: update)
}

func hover(to location: CLLocationCoordinate2D) {
   viewAllMarkers()
   mapView?.animate(toLocation: location)
}

But it does not work . It animates to a location but does not show all the markers in GMSMapView . How to do both at the same time ?

Mohammad Daihan
  • 538
  • 4
  • 15
  • Maybe this can help. https://stackoverflow.com/questions/49258862/put-multiple-markers-in-google-maps-swift – Abdul Momen Jan 11 '22 at 05:19
  • Well, not the easiest task. You will have to calculate difference between `bounds.center` and location, then take zoom into accout. Easier said than done, obviously. No easy workaround exist AFAIK – Dmytro Rostopira Jan 11 '22 at 10:45

0 Answers0