Tel +49 (30) 814504070

Dennis Bläsing
18.02.2012 22:59 Uhr

Snippet: Android Google Maps Bounding Box

Tags:

Using a bounding box in a Google Maps environment has certain advantages over operating only on geo points.

One of its biggest advantages is to capture the current map section without the need to worry about the zoom level.

Unfortunately, the Google Maps API in Android is not laid out to be used with a bounding box like you would expect as a Javascript API user - but it still can be put to good use.

You can use the map view projection to calculate the bounding box:

        Projection projection = mMapView.getProjection();
 
        // Get the point in the north west corner
        GeoPoint nw = projection.fromPixels(0, 0);
 
        // and the one in the lower left corner
        GeoPoint se = projection.fromPixels(mapView.getWidth(), mapView.getHeight());
 
        Integer north = nw.getLatitudeE6();
        Integer south = se.getLatitudeE6();
        Integer east = se.getLongitude();
        Integer west = nw.getLongitude();

Thanks to Dominik

Bookmark and Share

Comments

About CosmoCode

CosmoCode is a Berlin based IT service provider with a strong emphasis on web applications. We mainly focus on Content Management Systems, Wikis and custom solutions.

Subscribe

Subscribe Like our blog? Stay up to date via RSS
Freie Stelle: Fachinformatiker Freie Stelle: Fachinformatiker