Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API v2: LatLngBounds from CameraPosition

Is there a simple way to get the LatLngBounds of the visible map from a CameraPosition with Android Google Maps API v2 so that I can use the OnCameraChangeListener to go fetch new data for the markers.

mMap.setOnCameraChangeListener(new OnCameraChangeListener() {             @Override             public void onCameraChange(CameraPosition position) {                 LatLngBounds bounds = ?;                 fetchNewData(bounds);             }         }); 
like image 816
Garcon Avatar asked Dec 18 '12 20:12

Garcon


People also ask

What is Google Maps Latlngbounds?

An immutable class representing a latitude/longitude aligned rectangle.

How do I get data from Google Maps API?

Go to APIs & Services → Dashboard → Enable APIs & Services at the top and Choose Maps Javascript API from the API Library. This will open up the Map JavaScript API page, and Enable it.


1 Answers

You can't get the LatLngBounds from the CameraPosition, but you can get them easily from the GoogleMap.

private GoogleMap mMap;  mMap.setOnCameraChangeListener(new OnCameraChangeListener() {             @Override             public void onCameraChange(CameraPosition position) {                 LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;                 fetchData(bounds);             }         }); 
like image 136
Garcon Avatar answered Sep 23 '22 02:09

Garcon