Map zoom level for multiple markers

Hello there all thunkers,

I’m trying to control the zoom level of multiple custom markers in google maps.
What I need to do is to, after adding 2 or more markers in google map in my app, the zoom level would be accordingly leveled up (zoom out) so I can see them (ALL) in screen.

Is there any way to do this?
Any blocks or logic would be highly appreciated.

Thanks in advance

I think if you can figure out how many miles a zoom level shows across the map

Then figure out the distance between two points.

You could set the map accordingly

Thanks for your quick answer Jared,
that was a thought of mine too, but i want to somehow center my map so all of my markers could be visible.
And… is there any scale map documentation or anything, that points to how many miles shows in which zoom level?

That makes sense. These two links might answer your questions.

Thanks for the references and all the help Jared. I studied the very complex algorithm for geomidpoint (although I didn’t understand it) and logically it makes sense but I need to see the results in my screen after implement it in my code.
I’ll come back when I have any results.

Thanks again

I’m back (as I promised), just to thanks Jared, for his propositions. I finally managed to implement the mathematical type for finding the Midpoint of several points and in combination with a constructed scale of mine, I have almost the results I want, for showing multiple marks on map, in certain zoom level.
Yet, after that, I changed the mathematical type of the above complex midpoint algorithm with a much shorter code that works as good (if not better) from the first.
Just for future reference ,if anyone wants to use it, for finding midpoint of x points i used this formula :

map latitude = ((lat_max + lat_min) / 2
map longitude = ((lng_max + lng_min) / 2

Happy coding