erik
erik

Reputation: 4958

getting the center of a google map

I am using com.google.android.maps.v2

I am looking for a way to get the LatLng of the center of the viewable area of the map.

CustomMapFragment cusMapFrag;    
GoogleMap _map;

are set in my onCreate like so:

cusMapFrag = ((CustomMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map));    
_map = cusMapFrag.getMap();

I thought i use to be able to say _map.getCenter(); and that would return a lat and long for the center of the map view port.

I have tried: _map.getProjection().getVisibleRegion().... but there doesn't seem to be a center only: nearLeft, nearRight, farLeft, and farRight

Can anyone tell me how i can get the lat and long of the center of the viewable map?

Upvotes: 0

Views: 112

Answers (2)

mohammed momn
mohammed momn

Reputation: 3210

do you try this it depend on the pixel hope it help you

GeoPoint mapCenter = cusMapFrag.getProjection().fromScreenLocation(
    mapView.getWidth()/2,
    mapView.getHeight()/2);
int lat = mapCenter.getLatitudeE6();
int lon = mapCenter.getLongitudeE6();

and this method you can get the Point on map

Point myPoint = toScreenLocation(LatLng) ;

Upvotes: 2

erik
erik

Reputation: 4958

Ok so in my case the map is full screen, and i know my display width, height, and center. so this works for me: LatLng mapCenterLatLng = _map.getProjection().fromScreenLocation(centerOfScreen);

Upvotes: 0

Related Questions