Altaf
Altaf

Reputation: 5170

zoomToSpan implementation problem

I am using Google map in android where I am populating different markers on the map.In the mean time I am difficulty in implementing the zoom level which cover all the markers on the map.

Can anyone tell me the right way of implementing the zoomToSpan in android.

Upvotes: 2

Views: 995

Answers (1)

Femi
Femi

Reputation: 64700

You need to track the positions of all the markers to determine the proper bounds:

  1. Initialize 4 integers: the top and right bounds with Integer.MIN_VALUE, the bottom and left bounds with Integer.MAX_VALUE.
  2. Iterate over the position of all your markers and update the bounds appropriately: left should be the smallest latitude, right the largest latitude, bottom the smallest longitude, top the largest latitude (all these using the latitude E6 value).
  3. Pass zoomToSpan the difference between right and left and the difference between top and bottom, and you should be good.

You may need to do some extra work to manage centering the map properly so everything is in view, but that should about do it.

Upvotes: 3

Related Questions