Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Google Maps Api V2, getting the coordinates for the current map center

I am using Android Google Maps Api V2 (not MapView or MapActivity) and I am having difficulty getting the coordinates for the center of the map.

I was thinking of using

@Override
public void onCameraChange(CameraPosition arg0) {
    // TODO Auto-generated method stub
    geoCodeCenter(/*Location object*/);
}

but I can't get the lat/long from the CameraPosition object. the camera also has more dimensions as you can look at the map at different pitches now too, so getting the center of for latitude/longitude isn't the same since the user isn't guaranteed to be looking at the map from birds eye view, unless certain gestures are disabled.

Is there a better way to do this? I don't want the user to have to long click a marker to drag it around the map, I want them to just know where the center of the map is by the user panning it around.

the map.getMyLocation() method is for something else, like the current LocationProvider position. Also not seemingly the option, notwithstanding the fact that I am using GPS and it still returns null

like image 895
CQM Avatar asked Dec 20 '12 21:12

CQM


1 Answers

but I can't get the lat/long from the CameraPosition object

The target public data member on a CameraPosition is a LatLng of the map center, based upon my reading of the docs.

like image 176
CommonsWare Avatar answered Sep 24 '22 02:09

CommonsWare