Retrieve distance from visible part of Google map

Ale picture Ale · Dec 6, 2013 · Viewed 8.9k times · Source

I want to draw a static circle over a map with Google Maps. When the user pinches, the map will zoom in/out.

I need to know the map radius (related to the area contained in the circle) and change the seekbar at the bottom accordingly.

Does anybody know a solution how to retrieve the distance from the left to the right screen edge? I didn't find anything at the Google Maps API doc.

Something like this:

enter image description here

Answer

Md. Monsur Hossain Tonmoy picture Md. Monsur Hossain Tonmoy · Dec 6, 2013

using VisibleRegion you can get the all corner cordinates and also the center.

VisibleRegion vr = mMap.getProjection().getVisibleRegion();
double left = vr.latLngBounds.southwest.longitude;
double top = vr.latLngBounds.northeast.latitude;
double right = vr.latLngBounds.northeast.longitude;
double bottom = vr.latLngBounds.southwest.latitude;

and you can calcuate distance from two region by this

Location MiddleLeftCornerLocation;//(center's latitude,vr.latLngBounds.southwest.longitude)
Location center=new Location("center");
center.setLatitude( vr.latLngBounds.getCenter().latitude);
center.setLongitude( vr.latLngBounds.getCenter().longitude);
float dis = center.distanceTo(MiddleLeftCornerLocation);//calculate distane between middleLeftcorner and center 

enter image description here