views:

1352

answers:

4

Hi

We're building an application which is using the google maps api for android.

I have my MapController and MapView, and I enable the built-in zoom controls using:

mapView.setBuiltInZoomControls(true);

I would now like to get an event when the user actually zooms on the map, how do I go about that? I can find no such event or any general event where I could detect a change in zoom level.

Update

The mapView.getZoomControls() is deprecated. And the documentation suggests using mapView.setBuiltInZoomControls(bool) instead. This is okay, but I simply cannot figure out how to act on events from the built in zoom controls.

+1  A: 

The android API suggests you use ZoomControls which has a setOnZoomInClickListener()

To add these zoom controls you would:

ZoomControls mZoom = (ZoomControls) mapView.getZoomControls();

And then add mZoom to your layout.

JasonOfEarth
Thanks for the answer. The MapView.getZoomControls() is deprecated, with the suggestion of using the MapView.setBuiltInZoomControls(boolean) method. But I cannot find anywhere to get any events from these built-in zoom controls. Ref: http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapView.html#getZoomControls().
bjarkef
I see. Well it looks like there is an undocumented mapView.getZoomButtonsController() that you could use, described in http://code.google.com/p/android/issues/detail?id=3348 otherwise you'll just have to use the mapview.onkeydown and test for the zoom.
JasonOfEarth
I got what I wanted using the onUserInteraction event, and manually testing for a change in the zoom level. It works really nice with a toast message notifying the user of the necessity of zooming-in to view my overlay.
bjarkef
+2  A: 

As the OP said, use the onUserInteractionEvent and do the test yourself.

Wayne Young
A: 

You Can use

`ZoomButtonsController zoomButton = mapView.getZoomButtonsController();
    zoomButton.setOnZoomListener(listener);`

hope it helps

Felipe Conde
A: 

U can have Zoom CControl like this.

Here i am attaching code how u can implement zoomcontrol.

1>> XML file should be like this.

<com.google.android.maps.MapView 
    android:id="@+id/mapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="0l4sCTTyRmXTNo7k8DREHvEaLar2UmHGwnhZVHQ"
    />

<LinearLayout android:id="@+id/zoom" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    /> 

2>> On you main activity inside oncreate method do following things. here you are inflating your view with mapView

mapView = (MapView) findViewById(R.id.mapView); LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();

    zoomLayout.addView(zoomView, 
        new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, 
            LayoutParams.WRAP_CONTENT)); 
    mapView.displayZoomControls(true);

........................................................... This is how you can use inbuilt zoom control of API..

You can have your own custom code to implement Zoom in And Zoom out like this...

public boolean onKeyDown(int keyCode, KeyEvent event) { MapController mc = mapView.getController(); switch (keyCode) { case KeyEvent.KEYCODE_3: mc.zoomIn(); break; case KeyEvent.KEYCODE_1: mc.zoomOut(); break; } return super.onKeyDown(keyCode, event); }

..This is how i have implemented...

Thanks..Rakesh

Rakesh Gondaliya