1

I made custom buttons for zooming in and out. This is the XML for buttons:

<ImageButton
    android:id="@+id/unzoomButton"
    android:layout_width="58dp"
    android:layout_height="58dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:background="@drawable/unzoom_button"
    android:layout_marginTop="@dimen/standard_margin"
    android:layout_marginBottom="@dimen/standard_margin"
    android:scaleType="fitXY" />

<ImageButton
    android:id="@+id/zoomButton"
    android:layout_width="58dp"
    android:layout_height="58dp"
    android:layout_alignTop="@+id/unzoomButton"
    android:layout_toRightOf="@+id/unzoomButton"
    android:background="@drawable/zoom_button"
    android:scaleType="fitXY" />

Adding ImageButton listeners:

    imgbtnZoom = (ImageButton) findViewById(R.id.zoomButton);
    imgbtnZoom.setOnClickListener(this);

    imgbtnUnzoom = (ImageButton) findViewById(R.id.unzoomButton);
    imgbtnUnzoom.setOnClickListener(this);

And for statement that shozuld handles clicks:

@Override
public void onClick(View v) {

    switch (v.getId()) {
    case R.id.button_options:
        Intent i = new Intent();
        i.setClass(this, OptionsActivity.class);
        startActivityForResult(i, OptionsActivity.REQUEST_CODE_OPTIONS_ACTIVITY);
        break;
    case R.id.button_back:
        finish();
        break;
    case R.id.zoomButton:
        CameraUpdateFactory.zoomIn();
        Log.i("TAG", "Zoom in");
        break;
    case R.id.unzoomButton:
        CameraUpdateFactory.zoomOut();
        Log.i("TAG", "Zoom out");
        break;
    }
}

I even added log to those two clicks to make sure the button click actually works (and it does), but nothing happens with the map when I click either of those buttons.

CameraUpdateFactory.zoomIn() and CameraUpdateFactory.zoomOut() give you a CameraUpdate that changes the zoom level by 1.0, while keeping all other properties the same.

Google Maps API official documentation clearly states that using either of those two functions should zoom in/out google maps. It doesn't say that there should be anything else done for it to work. Am I missing something?

1 Answer 1

3

Just found a solution! This is how I've done it:

case R.id.zoomButton:
        mMap.animateCamera(CameraUpdateFactory.zoomIn());
        break;
case R.id.unzoomButton:
        mMap.animateCamera(CameraUpdateFactory.zoomOut());
        break;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.