Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android google map v2 moveCamera doesn't work

I'm trying to control Google map camera like this

private void setUpMap() {
        Log.e(LOG_TAG, "in setup method");
        mMap.setMyLocationEnabled(true);
        LatLng startingPoint = new LatLng(129.13381, 129.10372);
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(startingPoint, 16));
        Log.e(LOG_TAG, "in Setup method" + (mMapFragment == null));
    }

LogCat prints

"in setup method"

"in setup method false"

2 log is shown it means mMap.moveCamera(...) is called

setUpMap() call from here

private void setUpMapIfNeeded() {
        mMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag(MFragment.TAG);
        if (mMapFragment != null) {
            mMapFragment.getMapAsync(new OnMapReadyCallback() {
                @Override
                public void onMapReady(GoogleMap googleMap) {
                    mMap = googleMap;
                    setUpMap();
                }
            });
        }
    }
like image 541
user2637015 Avatar asked Feb 11 '23 15:02

user2637015


2 Answers

try this: hope it will work.

private void setUpMap() {
    Log.e(LOG_TAG, "in setup method"); 
    mMap.setMyLocationEnabled(true);
    CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(new LatLng(latitude, longitude)).zoom(15).build();
    mMap.animateCamera(CameraUpdateFactory
                .newCameraPosition(cameraPosition));
    Log.e(LOG_TAG, "in Setup method" + (mMapFragment == null));
}
like image 71
Mohsin Avatar answered Feb 15 '23 10:02

Mohsin


Your coordinates specified at LatLng startingPoint = new LatLng(129.13381, 129.10372); seems to be a bit off. In more detail, the maximum latitude is 90 degrees, which is the north pole (-90 is the south pole).

The result of this will be that the camera will not move to a position which is invalid.

Try using coordinates from a known location, such as LatLng startingPoint = new LatLng(55.70, 13.19); which will give you the position of Lund, Sweden.

So basically, revise the latitude and longitude coordinates for your position.

like image 35
Marcus Avatar answered Feb 15 '23 09:02

Marcus