2

I need to get the location of the center of my map-fragment. Of course it is not the center of the screen. I want to do something every time this location changes.

Every time the user moves/scrolls the map, I need the location of the center of my fragment and do something with them.

So, any Idea of how can I do that?

Thank you in advance for your help.

enter image description here

EDIT:

So I implemented OnCameraChangeListener and added onCameraChange but it never executes:

@Override
public void onCameraChange(CameraPosition arg0) {
    Log.v("tag", "onCameraChange");

    mLatitude = arg0.target.latitude;
    mLongitude = arg0.target.longitude;
    Log.v("tag", "onCameraChange  "+mLatitude+" "+mLongitude);

}
stanete
  • 4,062
  • 9
  • 21
  • 30

1 Answers1

1

I guess this should work:

mMap.getCameraPosition().target
Kody
  • 1,154
  • 3
  • 14
  • 31
  • Aha, I think this should work. But how can I execute a method overy time the cameraposition is changed? – stanete Feb 17 '14 at 08:34
  • 1
    Just implement the `OnCameraChangeListener` http://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.OnCameraChangeListener.html which provides the method `onCameraChange(CameraPosition pos)` – Kody Feb 17 '14 at 08:48
  • Actually it should work. Did you implement the onCameraChange method manually? Then you might have forgotten the @Override annotation. – Kody Feb 17 '14 at 09:28
  • I have set an OnCamaraChangeListener and it works. So ... Thank you. – stanete Feb 17 '14 at 10:42