Android Question Map: Diameter of circle displayed=screen width

toby

Well-Known Member
Licensed User
Longtime User
I want to adjust the zoom value according to a specified circle radius so that on the phone screen the circle covers the entire screen width, as the attached screenshot shows.

Here is where I'm stuck:
B4X:
'zoom in
    Dim zoom As Float=13 'how to calculate this value
                                     'so that the circle width is same or almost the same as screen width?
    Dim cp As CameraPosition
    cp.Initialize( latitude, longitude, zoom)
    gmap.AnimateCamera(cp)

Sample project attached.

TIA
 

Attachments

  • circleOnMap.small.jpg
    circleOnMap.small.jpg
    110.4 KB · Views: 157
  • circleOnMap.zip
    8.3 KB · Views: 142
Last edited:

klaus

Expert
Licensed User
Longtime User
You could do it this way:
B4X:
Private VisibleWidth, degCircle, Ratio As Double
Private OriginalZoom, Zoom As Float
Private LatLngB As LatLngBounds
OriginalZoom = gmap.CameraPosition.Zoom
LatLngB = gme.GetProjection(gmap).GetVisibleRegion.LatLngBounds    'Visible region bounds
VisibleWidth = Abs(LatLngB.SouthWest.Longitude - LatLngB.NorthEast.Longitude) 'width of the visible region on the screen
degCircle = 360 / 40075000 * radius * 2 / CosD(latitude) ' circle diameter in degrees
Ratio = Logarithm(VisibleWidth / degCircle, 2)    'ratio visible width / circle diameter
Zoom = OriginalZoom + Ratio    'optimum zoom

EDIT: amended the code and the project according to post #5 and #6.
 

Attachments

  • circleOnMap1.zip
    8.5 KB · Views: 177
Last edited:
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
Thank you @klaus for the code!

I tried it with different diameters (2000,5000,8000 & 10000) and the results I got are inconsistent. As shown in the attached screenshots, Diameter 5000 & 10000 gave me perfect results while the other two didn't. Did I miss something?
 

Attachments

  • radius2000.jpg
    radius2000.jpg
    70.6 KB · Views: 143
  • radius5000.jpg
    radius5000.jpg
    78 KB · Views: 144
  • radius8000.jpg
    radius8000.jpg
    63 KB · Views: 160
  • radius10000.jpg
    radius10000.jpg
    78.3 KB · Views: 138
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Change this line:
VisibleWidth = Abs(LatLngB.SouthWest.Latitude - LatLngB.NorthEast.Latitude)
to
VisibleWidth = Abs(LatLngB.SouthWest.Longitude - LatLngB.NorthEast.Longitude)

And this line, I had rounded the zoom to an integer value.
Ratio =Floor(Logarithm(VisibleWidth / degCircle, 2))
to
Ratio = Logarithm(VisibleWidth / degCircle, 2)

Sorry for the 'bad' solution.
I have updated the project and the code in post #4 and
 
Last edited:
Upvote 0
Top