user1032465
user1032465

Reputation: 117

How to get available Geolocations in current Zoomlevel in Google Maps for Android

how can i get the Latitude/Longitude values which are currently available in the actual zoomlevel by using GooleMaps API and Android? I do have the GeoLocations of all users on my map but i want to have only the users which are located on my current "Display" (Zoomlevel) therefore i have to know the Geo-Location boundaries for the actual Zoomlevel.

Upvotes: 1

Views: 232

Answers (2)

skynet
skynet

Reputation: 9908

You can use

int latSpanE6 = mapView.getLatitudeSpan();
int lonSpanE6 = mapView.getLongitudeSpan();

EDIT:

Oops, this is all useless without the center of the map:

GeoPoint center = mapView.getMapCenter();

int minMapLat = center.getLatitudeE6() - (latSpanE6/2);
int maxMapLat = center.getLatitudeE6() + (latSpanE6/2);
int minMapLon = center.getLongitudeE6() - (lonSpanE6/2);
int maxMapLon = center.getLongitudeE6() + (lonSpanE6/2);

Upvotes: 0

NickT
NickT

Reputation: 23873

Assuming you are only displaying a few square kilometres and not half the planet, then a decent approximation of the bounding box of your map view can be had with code such as:

GeoPoint topLeftGpt;
GeoPoint bottomRightGpt;

topLeftGpt = mapView.getProjection().fromPixels(0, 0);
bottomRightGpt = mapView.getProjection().fromPixels(mapView.getWidth(),
            mapView.getHeight());

If you then use the methods .getLatitudeE6() and .getLongitudeE6() on each of these Geopoints, it will give you the bounding box limits

Upvotes: 1

Related Questions