0

I need a way of getting the center Longitude of the current Google Map screen. I'm not dealing with any City scale but being able to scroll around the Atlantic and Western Pacific areas of the globe and being able to get a good enough center Longitude. And it needs to be reasonably updated as you scroll around.

This is on Android with Windows. I'm using the Android v2 API.

I have menu buttons that will take me to certain locations. And if you scroll all around after you go there, the calculated center Longitude usually stays the same but sometimes it does vary some.

On every dispatchDraw() I've tried using these operations to try to get the updated center Longitude:

They work once you go to that location, but if you scroll all around it tends to return the same initial value.

projection = googleMap.getProjection();
LatLng tCenterLatLng = 
projection.getVisibleRegion().latLngBounds.getCenter();
dCenterLongitude = tCenterLatLng.longitude;

CameraPosition cameraPosition = googleMap.getCameraPosition();
if ( cameraPosition != null )
{
    LatLng viewCenter = cameraPosition.target;
    Log.d(TAG, "viewCenter: "+viewCenter.longitude);
}
  

And I've also tried various OnCameraChangeListener, OnMapClickListener and OnCameraMoveListener and most only return a value once or twice.

Is there any other way to get anything from information about your scrolling? Or any lower level View information, because the above isn't working well enough.

UPDATE: With the code I have, I think it'll work good enough where the longitude does change some. I think that dispatchDraw() is being called so fast that the value doesn't seem to change much, but it does a little.

Thanks!

5
  • As you have mentioned, you are still using Maps SDK for Android V2, can you please confirm if you are still on the version 17.0? If so, what's keeping you from using the latest version of the Maps SDK?
    – Yrll
    Commented Feb 22 at 0:30
  • This is what I have: 'com.google.android.gms', name: 'play-services-maps', version: '18.0.0' My Key is pre "Want your Credit Card" Days.. Commented Feb 22 at 17:33
  • Why is OnCameraMoveListener no option? I did not check, but I think you need to fetch a new projection object each time the listener is called as the projection is most probably valid only for the current camera position. Commented Feb 24 at 14:44
  • OnCameraMoveListener isn't supported anymore. And at every dispatchDraw() I do an projection = googleMap.getProjection(); and use that. Commented Feb 26 at 18:29
  • It is recommended to use the latest version of the SDK to avoid using depracated or unsupported features. Please make sure to read the documentation to make sure that you're up to speed: developers.google.com/maps/documentation/android-sdk/overview
    – Yrll
    Commented Feb 27 at 5:50

0

Browse other questions tagged or ask your own question.