Issue
I have a MapFragment in my Android app and now I would like to know the min and max lat/long that is shown on the map actual.
I found this solution:
If you want to find out the longitude latitude of the corners of the MapView you could use:
Point mapCenter = mapView.getMapCenter();
int latitudeSpan = mapView.getLatitudeSpan() / 2;
int longitudeSpan = mapView.getLongitudeSpan() / 2;
int topLeftLat = mapCenter.getLatitudeE6() + (latitudeSpan);
int topLeftLon = mapCenter.getLongitudeE6() - (longitudeSpan);
int bottomLeftLat = mapCenter.getLatitudeE6() - (latitudeSpan);
int bottomLeftLon = mapCenter.getLongitudeE6() + (longitudeSpan);
My problem now is that I dont have a MapView, I only have a GoogleMap (com.google.android.gms.maps.GoogleMap) and a MapFragment (com.google.android.gms.maps.MapFragment) .
I need the min/max coordinates to do a DB query for selecting POI-DB-Entrys.
Solution
You can get it from your GoogleMap using getVisibleRegion from Projection.
Assuming you named your GoogleMap as map, you do
VisibleRegion bounds = map.getProjection().getVisibleRegion();
VisibleRegion is not necessarily a rectangle, but gives you the bounds, see the docs for more info.
Answered By - iagreen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.