Skip to content

Instantly share code, notes, and snippets.

@ThinhPhan
ThinhPhan / ZoomToFitMapAnnotations.md
Last active June 1, 2024 18:19
Zoom out to fit all annotations on MapView

I search a lot of questions and answers in SO. This is what i figure out. The result I want is map can zoom out to fit all/some annotations INCLUDE user's location.

The basic steps are:

  • Calculate the min lat/long
  • Calculate the max lat/long
  • Create CLLocation objects for these two points
  • Calculate distance between points
  • Create region using center point between points and distance converted to degrees